3

I'm trying to draw a dependency graph, I've followed this example, but I'm having difficulties with one node. I need node t to have two childs: r_vec and dR. However, I don't know how to link t and dR.

I have the following code:

\documentclass[a4paper]{article}

\usepackage{tikz}

\definecolor{pink}{RGB}{255,182,193}

\begin{document}

\begin{figure}
\begin{tikzpicture}[sibling distance=10em,
  every node/.style = {shape=rectangle, rounded corners,
    draw, align=center, minimum height=0.6cm,
    fill=pink}], level 7/.style={sibling distance=3cm}]
  \node {final\_image}
    child { node {complex\_image}
      child { node {interp\_result} 
        child { node {rc} 
          child { node {ph\_data} }}
        child { node {t} 
          child {node {r\_vec} } } } 
      child { node {ph\_corr} 
        child { node [right=1.5cm] {exp} 
          child { node {dR}
            child { node [left=1.3cm] {x\_dist}
              child { node {ant\_x} }
              child { node {x\_mat} }
            }
            child { node {y\_dist}
              child { node {ant\_y} }
              child { node {y\_mat} }
            }
            child { node [right=1.3cm] {z\_dist}
              child { node {ant\_z} }
              child { node {z\_mat} }
            }
          }
          child { node {min\_f}}
        }}};
\end{tikzpicture}
\end{figure}

\end{document}

that generates this graph:

enter image description here

I would also like to center the graph in the middle of the page, ignoring the margins, but don't know how to do that. I appreciate any help!

2 Answers 2

2

I added [name=t] and [name=dR] to name the interesting nodes and used:

\draw (t) edge (dR);

to draw an additional edge between these two nodes.

\documentclass{article}
\usepackage{tikz}
\definecolor{pink}{RGB}{255,182,193}

\begin{document}

\begin{figure}
\centering
\makebox[0pt]{%
  \begin{tikzpicture}[
  sibling distance=10em,
  every node/.style = {shape=rectangle, rounded corners,
    draw, align=center, minimum height=0.6cm,
    fill=pink}], level 7/.style={sibling distance=3cm}
  ]
  \node {final\_image}
    child { node {complex\_image}
      child { node {interp\_result}
        child { node {rc}
          child { node {ph\_data} }}
        child { node[name=t] {t}
          child {node {r\_vec} } } }
      child { node {ph\_corr}
        child { node [right=1.5cm] {exp}
          child { node[name=dR] {dR}
            child { node [left=1.3cm] {x\_dist}
              child { node {ant\_x} }
              child { node {x\_mat} }
            }
            child { node {y\_dist}
              child { node {ant\_y} }
              child { node {y\_mat} }
            }
            child { node [right=1.3cm] {z\_dist}
              child { node {ant\_z} }
              child { node {z\_mat} }
            }
          }
          child { node {min\_f}}
        }}};

  \draw (t) edge (dR);
  \end{tikzpicture}%
}
\end{figure}

\end{document}

enter image description here

6
  • I had no idea you could name nodes like that, this is exactly what I wanted. Thank you much for your help!
    – Hel
    Mar 19, 2020 at 23:48
  • Glad to help. :-)
    – frougon
    Mar 19, 2020 at 23:49
  • Glad...to upvoted you :-9
    – Sebastiano
    Mar 19, 2020 at 23:54
  • @Sebastiano Thanks and take care!
    – frougon
    Mar 19, 2020 at 23:56
  • 1
    @Sebastiano Yep, remote school also in France... hard times. :-/
    – frougon
    Mar 19, 2020 at 23:58
2

With forest is simpler to achieve the both of your goals, Also the code is far more concise:

\documentclass[a4paper]{article}
\usepackage{forest}
\definecolor{pink}{RGB}{255,182,193}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{figure}
    \centering
\begin{forest}
    for tree = {
% nodes
        draw, rounded corners, fill=pink,  minimum height=6mm, 
% tree        
   anchor = north,
    l sep = 7mm,
    s sep = 3mm,
tier/.option = level, % <--- corrected now
 where level = {5}{s sep=2mm}{}
                 }% end for tree
[final\_image
    [complex\_image 
        [interp\_result
            [rc
                [ph\_data]
            ]
            [t, name=t
                [r\_vec]
            ]
        ]
        [ph\_corr 
            [ , phantom]
            [exp
                [dR, name=dr
                    [x\_dist 
                        [ant\_x]
                        [x\_mat]
                    ]
                    [y\_dist
                        [ant\_y]
                        [y\_mat]
                    ]
                    [z\_dist 
                        [ant\_z]
                        [z\_mat]
                    ]
                ]
                [min\_f]
            ]
        ]
    ]
]
\draw   (t) -- ([xshift=-4pt] dr.north);
\end{forest}
\end{figure}
\end{document}

enter image description here

(red lines indicate text border)

Edit: Now MWE is corrected, added is lost coma in for specifications.

5
  • This is great, I like how much more compact it is than the method I used! Thank you so much for sharing.
    – Hel
    Mar 20, 2020 at 18:18
  • @Hell, you can upvote answer if you liked :-)
    – Zarko
    Mar 20, 2020 at 19:13
  • I was trying your code and I can't get it to compile, I keep getting the following error: ! LaTeX Error: Command \ShowFrameLinethickness undefined. and if I press enter I get this: ! Package forest Error: Circular tiers!. Any idea why this is happening?
    – Hel
    Mar 24, 2020 at 17:29
  • @Hel, ups, you are right. In provided code it seems that i didn't provide last version of code, since in it is missed one coma. Now corrected. Thank you to point mi on this error.
    – Zarko
    Mar 24, 2020 at 17:56
  • Thank you so much for answering, it's working now!
    – Hel
    Mar 24, 2020 at 23:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .