在使用算法绘图功能布置流程图时Tikz
,我的代码呈现以下输出(足以传达关键思想)。
现在,我打算将'no'
决策框 $x < y$ 的输出连接回节点iterative search
。但是,这样做时布局会变得混乱,导致以下输出。
我没有使用positioning
库并指定相对位置,而是选择使用 Tikz 的自动绘图功能,因为我需要连接大量节点和边。最后,我打算动态地尝试各种算法,以找到所需的算法。
因此,我正在寻找一个“可扩展”的解决方案(即不手动推动节点)来解决我的问题。
我LuaTex下面的代码是行号 52。您可以通过切换此行的注释字符串来获取两张图片。
\RequirePackage[l2tabu,orthodox]{nag}
\RequirePackage{luatex85}
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, fit, graphs, shapes, calc, arrows.meta, intersections}
\usetikzlibrary{graphdrawing}
\usegdlibrary{trees,layered,force}
\usepackage{mathtools}
\usepackage{circuitikz}
\newsavebox{\selectorswitch}
\begin{document}
\begin{tikzpicture}[
accregularnode/.style={draw,semithick, minimum width = 12mm, minimum height = 8mm},
accsumnode/.style={draw,circle,semithick},
accgainnode/.style={draw,isosceles triangle,semithick},
commongainnode/.style={draw,isosceles triangle,semithick,minimum size=1.5cm},
commonstylenode/.style={draw,semithick, minimum width = 1.2cm, minimum height = 1cm, node distance=4mm and 1.3cm},
commonstyledecisionbox/.style={draw,semithick,shape aspect=1,diamond,inner sep=2pt},
accstyledecisionbox/.style={draw,semithick,shape aspect=1,diamond,inner sep=2pt},
>=Stealth,auto
]
% \graph [binary tree layout,grow=right,components go right top aligned,edges=rounded corners,sibling distance=8mm,level distance=8mm]
\graph [layered layout,grow'=right,level sep=1cm,sibling sep=5mm]
{
{"accpower"/"a"[accregularnode],"dragpower"/"b"[accregularnode],"rollpower"/"c"[accregularnode],"gradpower"/"d"[accregularnode]}
-> "sumofpowers"/"$\Sigma$"[accsumnode]
-> [sloped] "scalebydteff"/"e" [accgainnode]
-> [sloped,parent anchor=east,] "powerselector"/"f" [draw,semithick]
-> [sloped] "scalebyncells"/"g" [commongainnode]
-> [sloped] "scalebysurfacearea"/"$\div$" [commonstylenode]
-> [sloped] "lionsimba"/"h" [align=center,commonstylenode];
;
"iterativesearchalgo"/"Iterative Search \\$n_{min}\le n^{(i)}\le n_{max}$"[commonstylenode,align=center]
->[sloped]"surfaceareacalc"/"i"[commongainnode]
->[sloped,parent anchor=east] scalebysurfacearea;
//[layered layout,grow=down,level sep=5mm]
{
lionsimba
-> "temperaturecheck"/"x<y" [align=center,commonstyledecisionbox]
->[edge label=\tiny{yes}] "cutoffvoltagecheck"/"p<q" [align=center,accstyledecisionbox]
->[edge label=\tiny{yes}]"cutoffsoccheck"/"m>n" [align=center,accstyledecisionbox]
->[edge label=\tiny{yes}] "noptaccgivenTcombo"/"long node name" [align=center,commonstylenode]
-> "noptgivenTcombo"/"very long node name" [double,align=right,commonstylenode]
};
temperaturecheck ->[parent anchor=west,child anchor=south,edge label= \tiny{no}] iterativesearchalgo;
};
\end{tikzpicture}
\end{document}