![LaTeX 中的简单流程图](https://linux22.com/image/409210/LaTeX%20%E4%B8%AD%E7%9A%84%E7%AE%80%E5%8D%95%E6%B5%81%E7%A8%8B%E5%9B%BE.png)
制作这个流程图简单吗?我需要将布局从 流程图到水平流程图。但我还是搞不清楚。
答案1
这是一种方法。它使用chains
,也许更重要的是eqparbox
确保所有节点的宽度相同,而无需手动输入宽度。必须编译两次才能获得正确的大小,因为eqparbox
记录了框的大小并将最大值写入辅助文件中,以便可以在第二次运行中使用。它通知用户需要第二次运行,并显示消息LaTeX Warning: Rerun to correct eqparbox widths.
无论如何,这是代码。
\documentclass[tikz,border=3mm]{standalone}
\usepackage{eqparbox}
\newbox\eqnodebox
\tikzset{equal size/.style={execute at begin
node={\setbox\eqnodebox=\hbox\bgroup},
execute at end node={\egroup\eqmakebox[#1][c]{\copy\eqnodebox}}},
equal size/.default=A}
\usetikzlibrary{arrows.meta,chains}
\begin{document}
\begin{tikzpicture}[node distance=1cm]
\begin{scope}[start chain=going below,
nodes={on chain,draw,minimum height=2.5em,inner xsep=1ex,
equal size,rounded corners,join,font=\sffamily},
every join/.style={-{Triangle[length=3mm,width=6mm]},line width=3mm,
gray!50,shorten >=1mm,shorten <=1mm}]
\node{Sample generation};
\node{Sample sample techniques};
\node{Sample sample techniques (AA and BB)};
\node{Sample sample techniques (AA and BB)};
\node{Sample sample techniques (AA and BB)};
\end{scope}
\end{tikzpicture}
\end{document}
答案2
考虑使用理智的蒂克兹。请参阅下面的代码。
import sane_tikz as stz
import formatting as fmt
box_height = 1.0
box_width = 7.0
box_spacing = 1.1
box_roundness = 0.1
shaft_width = 0.5
shaft_height = 0.4
head_width = 0.35
head_height = 0.8
lst = [
"Sample generation",
"Sample sample techniques",
"Sample sample techniques (AA and BB)",
"Sample sample techniques (AA and BB)",
"Sample sample techniques (AA and BB)",
]
def box_with_text(s):
s_fmt = fmt.rounded_corners(box_roundness)
return [
stz.rectangle([0, 0], [box_width, -box_height], s_fmt),
stz.latex([box_width / 2.0, -box_height / 2.0], s)
]
def arrow():
s_fmt = fmt.fill_color_with_no_line("lightgray")
a = stz.arrow(shaft_width, shaft_height, head_width, head_height, -90.0,
s_fmt)
return a
boxes = [box_with_text(s) for s in lst]
stz.distribute_vertically_with_spacing(boxes[::-1], box_spacing)
arrows = [arrow() for _ in range(len(lst) - 1)]
for i in range(len(boxes) - 1):
to_cs = stz.center_coords(boxes[i:i + 2])
from_cs = stz.center_coords(arrows[i])
stz.translate_to_coords(arrows[i], from_cs, to_cs)
stz.draw_to_tikz_standalone([boxes, arrows], "flowchart.tex")
生成的 TikZ 代码:
\documentclass{standalone}
\usepackage[T1]{fontenc}\usepackage{tikz}
\usepackage{amsmath, amsfonts}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\draw[rounded corners=0.100000cm] (0.000000, 8.400000) -- (7.000000, 8.400000) -- (7.000000, 7.400000) -- (0.000000, 7.400000) -- cycle;
\node[] at (3.500000,7.900000) {Sample generation};
\draw[rounded corners=0.100000cm] (0.000000, 6.300000) -- (7.000000, 6.300000) -- (7.000000, 5.300000) -- (0.000000, 5.300000) -- cycle;
\node[] at (3.500000,5.800000) {Sample sample techniques};
\draw[rounded corners=0.100000cm] (0.000000, 4.200000) -- (7.000000, 4.200000) -- (7.000000, 3.200000) -- (0.000000, 3.200000) -- cycle;
\node[] at (3.500000,3.700000) {Sample sample techniques (AA and BB)};
\draw[rounded corners=0.100000cm] (0.000000, 2.100000) -- (7.000000, 2.100000) -- (7.000000, 1.100000) -- (0.000000, 1.100000) -- cycle;
\node[] at (3.500000,1.600000) {Sample sample techniques (AA and BB)};
\draw[rounded corners=0.100000cm] (0.000000, 0.000000) -- (7.000000, 0.000000) -- (7.000000, -1.000000) -- (0.000000, -1.000000) -- cycle;
\node[] at (3.500000,-0.500000) {Sample sample techniques (AA and BB)};
\draw[fill=lightgray, draw=none] (3.700000, 7.275000) -- (3.700000, 6.775000) -- (3.900000, 6.775000) -- (3.500000, 6.425000) -- (3.100000, 6.775000) -- (3.300000, 6.775000) -- (3.300000, 7.275000) -- cycle;
\draw[fill=lightgray, draw=none] (3.700000, 5.175000) -- (3.700000, 4.675000) -- (3.900000, 4.675000) -- (3.500000, 4.325000) -- (3.100000, 4.675000) -- (3.300000, 4.675000) -- (3.300000, 5.175000) -- cycle;
\draw[fill=lightgray, draw=none] (3.700000, 3.075000) -- (3.700000, 2.575000) -- (3.900000, 2.575000) -- (3.500000, 2.225000) -- (3.100000, 2.575000) -- (3.300000, 2.575000) -- (3.300000, 3.075000) -- cycle;
\draw[fill=lightgray, draw=none] (3.700000, 0.975000) -- (3.700000, 0.475000) -- (3.900000, 0.475000) -- (3.500000, 0.125000) -- (3.100000, 0.475000) -- (3.300000, 0.475000) -- (3.300000, 0.975000) -- cycle;
\end{tikzpicture}
\end{document}