![如何像 Tikz 那样绘制用于输入和输出消息的特定形状?](https://linux22.com/image/314599/%E5%A6%82%E4%BD%95%E5%83%8F%20Tikz%20%E9%82%A3%E6%A0%B7%E7%BB%98%E5%88%B6%E7%94%A8%E4%BA%8E%E8%BE%93%E5%85%A5%E5%92%8C%E8%BE%93%E5%87%BA%E6%B6%88%E6%81%AF%E7%9A%84%E7%89%B9%E5%AE%9A%E5%BD%A2%E7%8A%B6%EF%BC%9F.png)
在算法表示中(几个月前我得到了帮助,感谢 tex.stackexchange!),我想使用 2 个特定符号表示输入和输出数据:这是实际的算法图:
Latex 源代码如下:
\documentclass{standalone}
\usepackage[T1]{fontenc} %lien codage fonte en sortie
\usepackage[latin1]{inputenc} %lien codage d'entrée
\usepackage{dejavu} % fonte en sortie
\usepackage{forest}
\usepackage{amssymb}
\usetikzlibrary{shapes.geometric}
\begin{document}
\pgfkeys{/forest,
racine/.append style={minimum width=1cm, fill=white!80,circle,
tikz={
\draw [circle,draw,line width=0.5pt] ;
\draw [->,line width=1pt] () ++(160:4mm) arc (-200:40:4mm);}
},
affecter/.append style={rectangle, minimum height=5mm},
ecrire/.append style={trapezium, trapezium left angle=110,trapezium right angle=70, minimum height=5mm},
lire/.append style={trapezium, trapezium left angle=70,trapezium right angle=-70, minimum height=5mm},
executer/.append style={below=0ex,draw,cloud,aspect=4,cloud puffs=32},
retourner/.append style={minimum width=2cm, fill=red!40,rectangle},
nop/.append style={circle},
sequence/.append style={fill=red!20, rounded corners},
decision/.append style={diamond, fill=blue!20, text width=5em, inner sep=.5pt, rounded corners},
si/.append style={fill=red!20, circle},
tq/.append style={fill=red!20, circle},
pour/.append style={fill=red!20, circle},
nuage/.append style={below=0ex,draw,dotted,cloud,aspect=4,cloud puffs=12}
}
\begin{forest}
for tree={
child anchor=north,
parent anchor=south,
thick,
draw,
align=center
}
[{CalculerSomme1\\\hline \mbox{}\\[-1em]VAR entier som,a,b,compteur\\} [seq, racine
[Initialisation, sequence[{a,b $\leftarrow$ }, lire][{som$\leftarrow$ 0}, affecter ] ]
[Traitement, sequence
[POUR, pour
[ { compteur\\de 1\\a b\\pas 1}, decision]
[repeter, sequence, edge label={node[midway,left,font=\scriptsize]{vrai}}[{som$\leftarrow$ som + a}, affecter ] ] ] ]
[Resultat, sequence[{ som}, ecrire] ] ] ]
\end{forest}
\end{document}
我想用符号替换输入 a 和 b,输出 som :你能帮助我吗?非常感谢!
答案1
这些形状已在shapes.symbols
库中可用,它们被称为signal
。请查看第 703 页pgfmanual
以下示例摘自该处:
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{shapes.symbols}
\begin{document}
\begin{tikzpicture}
[every node/.style={signal, draw, text=white, signal to=nowhere}]
\node[fill=green!65!black, signal to=east] at (0,1) {To East};
\node[fill=red!65!black, signal from=east] at (0,0) {From East};
\end{tikzpicture}
\end{document}