Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm creating yet another graph and I don't have particular problems. I can easily create the nodes, assign IDs and create arrows/paths using these IDs. But when there is a lot of content and there is a need of doing the "same work" over and over, I think that many would try to look for a way to do this using some "abbreviation-commands", in order to automatize everything and avoid writing the same code.

So, I am doing something like this:

mock-up image

Instead of writing \draw (node) -- (node1); over and over, changing the ID as I go on, is there a way to tell LaTeX to make as many arrows "from node on the left to main node" as needed?

In case this is not possible (but I trust LaTeX and the experts here), please post an answer stating it, so I can accept it anyway and spare some headache hours to others with my "problem".

So all A# nodes must point to the Main node inf while the b# nodes to the part one. Here's my code:

\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}
share|improve this question
1  
I'd be strongly tempted to create all the nodes in a loop as well. –  Loop Space Jun 7 '12 at 9:20
    
@AndrewStacey Would that be possible considering the nodes' content is different? –  Alenanno Jun 7 '12 at 9:21
1  
Yes. The first node in a set has to be done manually, but for all the others I would do something like \foreach[count=\i from 2,count=\prev from 1] \txt in {all,the,nodes,contents} {\node[draw=none,fill=none, below of= a\prev] (a\i) {\txt};}. (Haven't checked the syntax - not so used to \foreachs.) –  Loop Space Jun 7 '12 at 9:24

1 Answer 1

up vote 4 down vote accepted

To automate a process you need to use the foreach. In your case it is very simple since you have been very clear in assigning labels to nodes.

You simply have to add to your code:

\foreach \x in {1,...,26}
\draw[-stealth] (a\x)--(inf.west);

\foreach \y in {1,...,9}
\draw[-stealth] (b\y)--(part.west);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.