2

I want to create a figure where I have multiple nodes of text and make them look like a proper multi-line text.

Essentially I need two things:

  1. Figure out the proper node distance to use (I got this by dumping \the\baselineskip).
  2. Arrange all nodes to use that distance.

I can make this work if every node has only one line:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,trees,positioning,arrows, fit}
\begin{document}
    \begin{tikzpicture}[]
            \begin{scope}[
                    node distance   = 18.0pt,
            ]
            \node[rectangle, font=\huge] (Title) {Title};
            \node[inner sep=0, font=\Large, align=left] (start) [below=of Title] {Hello};
            \node[inner sep=0, font=\Large, align=left] (mid) [below=of start.west,anchor=west] {Hi};
            \node[inner sep=0,font=\Large, align=left] (end) [below=of mid.west,anchor=west] {Bye};
            \end{scope}
    \end{tikzpicture}
\end{document}

However if there are nodes with multiple lines then there are overlaps:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,trees,positioning,arrows, fit}
\begin{document}
    \begin{tikzpicture}[]
            \begin{scope}[
                    node distance   = 18.0pt,
            ]
            \node[rectangle, font=\huge] (Title) {Title};
            \node[inner sep=0, font=\Large, align=left] (start) [below=of Title] {Hello};
            \node[inner sep=0, font=\Large, align=left] (mid) [below=of start.west,anchor=west] {Hi};
            \node[inner sep=0,font=\Large, align=left] (end) [below=of mid.west,anchor=west] {Bye \\ Bye \\ Bye};
            \end{scope}
    \end{tikzpicture}
\end{document}

Obviously I want to avoid splitting all text to single-line nodes and I don't want to manually use yshift to fix the distances. Any ideas?

Thanks in advance!

  • 1
    Welcome to TeX.SE! Assuming you know that you can write in a given node multiple nodes, I wonder what you like to achieve. BTW, are you aware of shapes.multipart? – user121799 Oct 6 '18 at 16:24
1

If you position the nodes relative to appropriate anchors, no overlaps happen.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
    \begin{tikzpicture}[]
            \begin{scope}[
                    node distance   = 6pt,
            ]
            \node[rectangle, font=\huge,anchor=south west] (Title) {Title};
            \node[inner sep=0, font=\Large, align=left] (start) [below=of
            Title.south west,anchor=north west] {Hello};
            \node[inner sep=0, font=\Large, align=left] (mid) [below=of
            start.south west,anchor=north west] {Hi};
            \node[inner sep=0,font=\Large, align=left] (end) 
            [below=of mid.south west,anchor=north west] {Bye \\ Bye \\ Bye};
            \end{scope}
    \end{tikzpicture}
\end{document}

enter image description here

However, I am not sure I understand the purpose. Are you by chance looking for shapes.multipart or matrix?

  • Thanks a lot for the help! I think I need different nodes because later on I want to format some of them in a different way, but I'll definitely take a look at your suggestions. Thanks again! – Mar Pom Oct 6 '18 at 16:38
0

you can connect nodes in chain:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{chains, positioning}

\begin{document}
    \begin{tikzpicture}[
    start chain = going below left,
    node distance = 6pt and 0pt
                        ]
        \node[font=\huge,anchor=south west] (Title) {Title};
        \begin{scope}[every node/.append style = {
                font=\Large, align=left, inner sep=0pt,
                on chain, anchor=north west}
                      ]
        \node[below=of Title.south west] {Hello};
        \node {Hi};
        \node {Bye \\ Bye \\ Bye};
        \end{scope}
    \end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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