我正在创建另一个图表,没有遇到什么特别的问题。我可以轻松创建节点、分配 ID 并使用这些 ID 创建箭头/路径。但是当内容很多并且需要一遍又一遍地做“相同的工作”时,我认为许多人会尝试使用一些“缩写命令”来寻找一种方法来做到这一点,以便自动化一切并避免编写相同的代码。
因此,我正在做这样的事情:
有没有办法告诉 LaTeX 制作尽可能多的箭头,而不是\draw (node) -- (node1);
一遍又一遍地写,一边写一边改变 ID“从左侧节点到主节点”如所须?
如果这不可能(但我相信 LaTeX 和这里的专家),请发表一个答案说明这一点,这样我就可以接受它,并为其他遇到我的“问题”的人省去一些头痛的时间。
因此,所有A#
节点必须指向主节点,inf
而其他b#
节点则指向一个节点part
。这是我的代码:
\documentclass{article}
\usepackage[a4paper, margin=1cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{rotating}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{shapes,snakes,arrows,positioning,
calc}
\begin{document}
\pagestyle{empty}
\begin{tikzpicture}[scale=2]
\begin{scope}[node distance=5mm,
every node/.style={align=left,text width=10em}]
\node[draw=none,fill=none] (a1) {acabar de};
\node[draw=none,fill=none, below of= a1] (a2) {acabar por};
\node[draw=none,fill=none, below of= a2] (a3) {comenzar a};
\node[draw=none,fill=none, below of= a3] (a4) {darle (a uno) por};
\node[draw=none,fill=none, below of= a4] (a5) {deber};
\node[draw=none,fill=none, below of= a5] (a6) {deber de};
\node[draw=none,fill=none, below of= a6] (a7) {dejar de};
\node[draw=none,fill=none, below of= a7] (a8) {echar(se) a};
\node[draw=none,fill=none, below of= a8] (a9) {empezar a};
\node[draw=none,fill=none, below of= a9] (a10) {estar a punto de};
\node[draw=none,fill=none, below of= a10] (a11) {estar para};
\node[draw=none,fill=none, below of= a11] (a12) {estar por};
\node[draw=none,fill=none, below of= a12] (a13) {haber (3a persona) + que};
\node[draw=none,fill=none, below of= a13] (a14) {haber de};
\node[draw=none,fill=none, below of= a14] (a15) {Ir a};
\node[draw=none,fill=none, below of= a15] (a16) {llegar a};
\node[draw=none,fill=none, below of= a16] (a17) {meterse a};
\node[draw=none,fill=none, below of= a17] (a18) {pasar a};
\node[draw=none,fill=none, below of= a18] (a19) {pensar};
\node[draw=none,fill=none, below of= a19] (a20) {ponerse a};
\node[draw=none,fill=none, below of= a20] (a21) {quedar en};
\node[draw=none,fill=none, below of= a21] (a22) {romper a};
\node[draw=none,fill=none, below of= a22] (a23) {tener que};
\node[draw=none,fill=none, below of= a23] (a24) {tratar de};
\node[draw=none,fill=none, below of= a24] (a25) {venir a};
\node[draw=none,fill=none, below of= a25] (a26) {volver al};
\end{scope}
\begin{scope}[node distance=5mm,
every node/.style={align=left,text width=10em,draw}]
\node[draw=none,fill=none, below of= a26] (b1) {andar};
\node[draw=none,fill=none, below of= b1] (b2) {continuar};
\node[draw=none,fill=none, below of= b2] (b3) {estar};
\node[draw=none,fill=none, below of= b3] (b4) {ir};
\node[draw=none,fill=none, below of= b4] (b5) {llevar};
\node[draw=none,fill=none, below of= b5] (b6) {quedarse};
\node[draw=none,fill=none, below of= b6] (b7) {seguir};
\node[draw=none,fill=none, below of= b7] (b8) {venir};
\node[draw=none,fill=none, below of= b8] (b9) {verse};
\end{scope}
\begin{scope}[node distance=7cm,
every node/.style={align=center,text width=2cm,draw}]
\node[rectangle, right of= a14] (inf) {Infinitivo};
\node[rectangle, right of= b5] (part) {Participio};
\end{scope}
\end{tikzpicture}
\end{document}
答案1
要使流程自动化,您需要使用foreach
。对于您来说,这非常简单,因为您已经非常清楚地为节点分配了标签。
您只需要在代码中添加:
\foreach \x in {1,...,26}
\draw[-stealth] (a\x)--(inf.west);
\foreach \y in {1,...,9}
\draw[-stealth] (b\y)--(part.west);