Latex画流程图、状态图记录

这篇博客分享了如何使用LaTeX的TikZ库来绘制复杂的流程图,包括定义箭头样式、绘制圆形节点和文字,并提供了两个实例。通过学习LaTeX,可以制作出比Visio更美观的图表,同时介绍了数学符号的使用。
摘要由CSDN通过智能技术生成

临时要画个图,latex接触不多,代码比较繁琐。有空的话好好学习一下,会用了画图比visio更好看些。
我画的第二张图:
在这里插入图片描述
画这张图我参考的:
LaTeX修改字体大小
框图案例
TiKZ 线条绘制的控制
框图案例2
TikZ画箭头、网格、圆、点、椭圆、圆弧

代码:


\documentclass[UTF8]{article}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows,arrows.meta}



\begin{document}
	%定义箭头样式一:颜色、线的粗细、剪头的样式(箭头长度、宽度)
	\tikzset{
		arrow1/.style = {
			draw =black, semithick, -{Stealth[length = 3mm, width = 2mm]},
		}	
	}
	%定义箭头样式二:颜色、线的粗细、虚线、剪头的样式(箭头长度、宽度)
	\tikzset{
	arrow2/.style = {
		draw =black, semithick,densely dashed,-{Stealth[length = 3mm, width = 2mm]},
		}	
	}
	
	\begin{tikzpicture}[]
%    画个辅助网格,可以用坐标控制很多东西
%	\draw[help lines] (-7 ,-7) grid ( 7, 7); 	
	%第一排文字,图方便直接用坐标
	\node[]at(-5,3.2){\LARGE $s_i$};
	\node[]at(-2.5,3.2){\LARGE $y_i$};
	\node[]at(0,3.2){\LARGE $s_{i+1}$};
	\node[]at(2.5,3.2){\LARGE $y_{i+1}$};
	\node[]at(5,3.2){\LARGE $s_{i+2}$};
	
	%画第一排圆形框
	
	%确定第一个圆的坐标后,就可以用节点的相对位置了,方便对齐。用坐标还得算。
	%这个应该可以在前面定义好节点的样式,这里直接用,我没弄明白,就先这样弄吧
	%节点的形状、边框线和文字的距离、label distance不知道是啥
	
	\node [draw, circle,inner sep=0.22cm,label distance = 0.05cm]at(-5,2) (a1){\huge 0};
	%相对位置、节点的形状、边框线和文字的距离、节点间的距离、on grid好像是保证节点都在整数坐标上吧
	\node[right of=a1,draw,circle,inner sep=0.22cm,node distance=5cm,on grid](a2) {\huge 0};
	\node[right of=a2,draw,circle,inner sep=0.22cm,node distance=5cm,on grid](a3) {\huge 0};
	
	%画第二排圆形节点
	\node[below of=a1,draw,circle,inner sep=0.22cm,node distance=3cm,on grid](b1) {\huge 1};
	\node[right of=b1,draw,circle,inner sep=0.22cm,node distance=5cm,on grid](b2) {\huge 1};
	\node[right of=b2,draw,circle,inner sep=0.22cm,node distance=5cm,on grid](b3) {\huge 1};
	
	%画实线箭头
	%箭头旁边的文字位置可控:
	%这里写在箭头出发节点的旁边,离它多远就调整xshift、yshift
	
	\draw[arrow1](a1)node[above,xshift = 30pt]{\Large 0} -- (a2);	
	\draw[arrow1](a2)node[above,xshift = 30pt]{\Large 0} -- (a3);
	\draw[arrow1](b1)node[above,xshift = 30pt,yshift=18pt]{\Large 2} -- (a2);
	\draw[arrow1](b2)node[above,xshift = 30pt,yshift=18pt]{\Large 2} -- (a3);
	
	%画虚线箭头
	\draw[arrow2](a1)node[below,xshift = 28pt,yshift=-17pt]{\Large -2} -- (b2);
	\draw[arrow2](b1)node[below,xshift = 30pt]{\Large 0} -- (b2);
	\draw[arrow2](a2)node[below,xshift = 28pt,yshift=-17pt]{\Large -2} -- (b3);
	\draw[arrow2](b2)node[below,xshift = 30pt]{\Large 0} -- (b3);
	
	\end{tikzpicture}
\end{document}


我画的第一张图:
在这里插入图片描述
代码:

\documentclass[UTF8]{article}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows,arrows.meta}



\begin{document}
	
	\begin{tikzpicture}[semithick]

%	\draw[help lines] (-7 ,-7) grid ( 7, 7); 	
	\node [draw=gray, inner sep=0.4cm,fill=gray!50,label=above: \rmfamily{\LARGE  $c_1$}] (c1) at (-2,5){};
	\node [draw=gray, inner sep=0.4cm,fill=gray!50,label=above:\LARGE $c_2$] (c2) at (0,5){};
	\node [draw=gray, inner sep=0.4cm,fill=gray!50,label=above:\LARGE $c_3$] (c3) at (2,5){};
	
	\node [draw, circle,inner sep=0.35cm,label distance = 0.01cm,label=left:\LARGE $u_1^1$]at(-5,2) (u1){ };
	\node[right of=u1,draw,circle,inner sep=0.35cm,node distance=2cm,on grid,label=left:\LARGE $u_2^1$](u2) {};
	\node[right of=u2,draw,circle,inner sep=0.35cm,node distance=2cm,fill=gray!50,on grid,label=left:\LARGE $u_3^1$](u3) {};
	\node[right of=u3,draw,circle,inner sep=0.35cm,node distance=2cm,on grid,label=left:\LARGE $u_4^1$](u4) {};
	\node[right of=u4,draw,circle,inner sep=0.35cm,node distance=2cm,on grid,label=left:\LARGE $u_5^1$](u5) {};
	\node[right of=u5,draw,circle,inner sep=0.35cm,node distance=2cm,fill=gray!50,on grid,label=left:\LARGE $u_6^1$](u6) {};
	
	\node[below of=u1,draw,circle,inner sep=0.2cm,node distance=2cm,on grid](u11) {+};
	\node[right of=u11,draw,circle,inner sep=0.2cm,node distance=2cm,on grid](u22) {+};
	\node[right of=u22,draw,circle,inner sep=0.2cm,node distance=2cm,on grid](u33) {+};
	\node[right of=u33,draw,circle,inner sep=0.2cm,node distance=2cm,on grid](u44) {+};
	\node[right of=u44,draw,circle,inner sep=0.2cm,node distance=2cm,on grid](u55) {+};
	\node[right of=u55,draw,circle,inner sep=0.2cm,node distance=2cm,on grid](u66) {+};
	
	\node[below of=u11,draw,circle,inner sep=0.35cm,node distance=3cm,on grid,label=below:\LARGE $s_1$](s1) {};
	\node[right of=s1,draw,circle,inner sep=0.35cm,node distance=2cm,on grid,label=below:\LARGE $s_2$](s2) {};
	\node[right of=s2,draw,circle,inner sep=0.35cm,node distance=2cm,on grid,label=below:\LARGE $s_3$](s3) {};
	\node[right of=s3,draw,circle,inner sep=0.35cm,node distance=2cm,on grid,label=below:\LARGE $s_4$](s4) {};
	\node[right of=s4,draw,circle,inner sep=0.35cm,node distance=2cm,on grid,label=below:\LARGE $s_5$](s5) {};
	\node[right of=s5,draw,circle,inner sep=0.35cm,node distance=2cm,on grid,label=below:\LARGE $s_6$](s6) {};
	
	\draw [](c1)--(u1)--(u11)--(s1);
	\draw [](c1)--(u2)--(u22)--(s2);
	\draw [](c1)--(u4);	

	
	\draw [](c2)--(u1);
	\draw [](c2)--(u4)--(u44)--(s4);
	\draw [](c2)--(u5)--(u55)--(s5);
	
	\draw [](c3)--(u2);
	\draw [](c3)--(u5);
	
	\draw [](u3)--(u33)--(s3);
	\draw [](u6)--(u66)--(s6);	
	\draw [](u11)--(u22)--(u33)--(u44)--(u55)--(u66);	
	\draw [](s1)--(s2)--(s3)--(s4)--(s5)--(s6);	
	

	
	\draw[-{Stealth[length=2.5mm]}] (-5,3) -- (-3,5); 
	\node[]at(-4.5,4.2){\LARGE $q_{ln}^x$};
	\draw[-{Stealth[length=2.5mm]}] (3,5) -- (5,3)node [midway,right]{\LARGE $r_{ln}^x$}; 
	
	\draw[-{Stealth[length=2.5mm]}] (-6.3,0) -- (-6.3,2)node [midway,left]{\LARGE $t_n^{,x}$}; 
	\draw[-{Stealth[length=2.5mm]}] (-6.3,-3) -- (-6.3,-1)node [midway,left]{\LARGE $t_n^x$}; 

	\draw[-{Stealth[length=2.5mm]}] (6.5,2)--(6.5,0)  node [midway,right]{\LARGE $g_n^{,x}$}; 
	\draw[-{Stealth[length=2.5mm]}] (6.5,-1)--(6.5,-3) node [midway,right]{\LARGE $g_n^x$}; 	


	\draw[-{Latex[length=3mm]}]  (-4,-1.5)node [below] {\LARGE $u_1^2$}--(-4.7,-0.3);
	\draw[-{Latex[length=3mm]}]  (-2,-1.5)node [below] {\LARGE $u_2^2$}--(-2.7,-0.3);
	\draw[-{Latex[length=3mm]}]  (0,-1.5)node [below] {\LARGE $u_3^2$}--(-0.7,-0.3);
	\draw[-{Latex[length=3mm]}]  (2,-1.5)node [below] {\LARGE $u_4^2$}--(1.3,-0.3);
	\draw[-{Latex[length=3mm]}]  (4,-1.5)node [below] {\LARGE $u_5^2$}--(3.3,-0.3);
	\draw[-{Latex[length=3mm]}]  (6,-1.5)node [below] {\LARGE $u_6^2$}--(5.3,-0.3);
		
	\end{tikzpicture}
\end{document}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值