Latex中画出函数文件的调用关系拓扑图

流程图,思维导图,拓扑图通常能把我们遇到的一些复杂的关系结构用图形的方式展现出来。在Latex中要想画这样的拓扑图,有一个很好用的绘图工具包 pgf/tikz 。

1.pgf/tikz的安装:pgf/tikz 绘图工具用到的宏是 usepackage{tikz} 。如果你的Latex并不带有这个宏包,那就需要参考[1]中进行安装。也可以直接下载使用带有这个宏包的新版本 CTeX_2.9.2.164_Full。

2.pgf/tikz的使用:参考[2]pgf/tikz使用说明,这里详细介绍了pgf/tikz的各种用法。

利用Latex绘制函数关系的图

documentclass{report}
usepackage{pgf}
usepackage{tikz}
usepackage{listings}
usepackage{xcolor}
usepackage{graphicx}

usetikzlibrary{shapes.callouts}
usetikzlibrary{arrows,decorations.pathmorphing, backgrounds, positioning, fit, petri, automata}
definecolor{yellow1}{rgb}{1,0.8,0.2}
lstset{
    basicstyle=footnotesize,
    framexleftmargin=1.5mm,
    keywordstyle=color{blue}fseries,
    identifierstyle=f,
    commentstyle=itcolor[RGB]{96,96,96},
    stringstyle=
mfamilyslshapecolor[RGB]{128,0,0},
    showstringspaces=false
}

egin{document}
egin{tikzpicture}
[remember picture, note/.style={ellipse callout, fill=#1},
->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,semithick]

	ikzstyle{every state}=[rectangle,fill=yellow1,draw=none,text=black]

%创建对象:
ode(对象属性)   (对象名称)  at (对象坐标) {对象内容};

ode[state]         (fun_main) at (-32, 16)        {
egin{lstlisting}[language={C}]
#include<stdio.h>
#include "func.h"

void main(void)
{
   int a,b,ans;
   int flag;
 scanf("%d%d%d",&a,&b,&flag);
 switch(flag)
 {
   case 0 :
        {ans = Sum(a,b);}
        break;
   case 1 :
        {ans = Product(a,b);}
        break;
 }
 printf("ans=%d
",ans);
}
end{lstlisting}
};

ode[state,fill=none]         (filename_main) at ([yshift=0.2cm]fun_main.north)        {$Funcunderline{hspace{0.5em}}main.c$};


ode[state]         (fun0) at (-26.5, 17)        {
egin{lstlisting}[language={C}]
int Sum(int a,
        int b );
        
int Product(int a,
            int b );
end{lstlisting}
};

ode[state,fill=none]         (file0) at ([yshift=0.2cm]fun0.north)        {$Func.h$};


ode[state]         (fun1) at (-22, 18)        {
egin{lstlisting}[language={C}]
#include<stdio.h>
int Sum(int a,int b)    
{   int c;
    c = a+b;
    return c;
 }
end{lstlisting}
};

ode[state,fill=none]         (file1) at ([yshift=0.2cm]fun1.north)        {$Funcunderline{hspace{0.5em}}sum.c$};


ode[state]         (fun2) at (-21.6, 14)        {
egin{lstlisting}[language={C}]
#include<stdio.h>
int Product(int a,int b)
{   int c;
    c = a*b;
    return c;
 }
end{lstlisting}
};

ode[state,fill=none]         (file2) at ([yshift=0.2cm]fun2.north)        {$Funcunderline{hspace{0.5em}}product.c$};

%
ode[标注填充颜色,相对标注对象坐标,边框] (标注对象名称) at (标注对象的坐标) {内容};

ode[note=green!50, callout relative pointer={(-0.5,0.5)}, draw] (note_name)at (-28,14) {
egin{lstlisting}[language={C}]
Start from 
main!
end{lstlisting}
};


%箭头:([横平移,纵平移]箭头端点相对对象1的位置) (out:箭头出射角度,int:箭头入射角度) ([横平移,纵平移]箭头端点相对对象2的位置);
draw[->] ([xshift=-2.0cm,yshift=-0.6cm]fun_main.north east) to[out=0,in=180]  ([xshift=0cm,yshift=0cm]fun0.west);
draw[->] (fun0.east) to[out=0,in=210]  ([xshift=0.2cm,yshift=-0.6cm]fun1.north west);
draw[->] (fun0.east) to[out=0,in=150]  ([xshift=0.2cm,yshift=-0.6cm]fun2.north west);
end{tikzpicture}
end{document}

  排版出来的效果如下

参考:

[1] http://blog.csdn.net/mathsoperator/article/details/6747170
[2] http://mirror.lzu.edu.cn/CTAN/graphics/pgf/base/doc/pgfmanual.pdf

[3] Latex论坛,http://tex.stackexchange.com/

原文地址:https://www.cnblogs.com/abc36725612/p/5990269.html