1

I want to vertical align text in a chain of nodes. One node has a linebreak. What is the best way to do this? This is my current example:

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{chains}
\begin{document}
    \begin{tikzpicture}[
        start chain,
        every node/.style={
            draw,
            text height=1.5ex,
            text depth=.0ex,
            text width=7em,
            text centered,
            anchor=base,
            minimum height=3em
        }]

        \node[on chain, join] {node with\\linebreak};
        \node[on chain, join] {node};
    \end{tikzpicture}
\end{document}

I want my first node to be vertically aligned.

2

Like this?

enter image description here

The code of above image is:

\documentclass[border=3mm, tikz]{standalone}
\usetikzlibrary{chains}

\begin{document}
    \begin{tikzpicture}[
      start chain = going right,
every node/.style = {
    draw,
    minimum height=3em,
    text width=7em,
    align=center,
    on chain, join}
            ]
        \node  {node with\\linebreak};
        \node  {node};
    \end{tikzpicture}
\end{document}

As you can see, I only change parameters of your every node/.style .... If you define text height and depth, than TikZ use text height for the first line of text and other lines put below it. So better is to declare minimum height=.... New syntax for text centering is align=center.

0

You could use a minipage to allow the line break within the node.

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{chains}
\begin{document}
    \begin{tikzpicture}[
        start chain,
        every node/.style={
            draw,
            text height=1.5ex,
            text depth=.0ex,
            text width=7em,
            text centered,
            anchor=base,
            minimum height=3em
        }]

        \node[on chain, join] {\begin{minipage}{\textwidth}\centering
        node with \\ linebreak
        \end{minipage}};
        \node[on chain, join] {node};
    \end{tikzpicture}
\end{document}

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.