1

In order to configure a node's line spacing for multi-line text I am forced to preface the text with \baselineskip=2.5ex and append an additional \par after it inside every single node. Is there a way to avoid doing this repeatedly?

\documentclass{report}
\usepackage{tikz}
  \usetikzlibrary{calc,fit,positioning}
\begin{document}

\begin{tikzpicture}[
    remember picture, overlay,
    every node/.style={fill=green, font=\large}
      ]
  \node (N0)
    at (0,0)
    {Start}; % <- That's what I want for multi-line text: Only the text
  \node[right=of N0, text width=3cm, align=center] (N1)
    {\baselineskip=2.5ex Looooooooooong multi-line text.\par}; % <- That's what's required
  \node[right=of N1, text width=3cm, align=center] (N2)
    {\baselineskip=2.5ex Another looooooooooong multi-line text.\par};
\end{tikzpicture}

\end{document}

Are there node style parameters to define such pre- and postfix commands? There exist postaction and preactions parameters which don't help me. The following code does not produce correct linespacing (the \par seems to be ignored).

%...
    every node/.style={fill=green, font=\large, postaction={\par}}
%...
  \node[right=of N1, text width=3cm, align=center] (N2)
    {\baselineskip=2.5ex Another looooooooooong multi-line text.};
%...

Any ideas?

Jersey
  • 113
  • Welcome to tex.sx. Although the code snippets you show are quite detailed, it's not easy for potential helpers to actually debug it. Please extend your example to a small, easily compilable file, starting with \documentclass and ending with \end{document}, that can be copy-pasted for experimentation. – barbara beeton Dec 20 '19 at 14:10
  • @barbarabeeton Did so, thanks! – Jersey Dec 20 '19 at 15:00

2 Answers2

2

You can use font. See whether this works for you. I use \baselineskip=5ex to emphasize the difference.

\documentclass{report}
\usepackage{tikz}
  \usetikzlibrary{calc,fit,positioning}
\begin{document}

\begin{tikzpicture}[
    remember picture, overlay,
    every node/.style={fill=green, font=\large},
    baselineskip/.style={font={\large\baselineskip=#1}}
  ]
  \node (N0)
    at (0,0)
    {Start}; % <- That's what I want for multi-line text: Only the text
  \node[right=of N0, text width=3cm, align=center,baselineskip=5ex] (N1)
    {Looooooooooong multi-line text.}; % <- That's what's required
  \node[right=of N1, text width=3cm, align=center,baselineskip=5ex] (N2)
    {Another looooooooooong multi-line text.};
\end{tikzpicture}

\end{document}

enter image description here

fractal
  • 1,500
  • That's it! Thanks a lot. Although it solves my actual problem, it does not answer the question. I'll wait a little bit before I accept the answer. Maybe someone else will chime in. – Jersey Dec 20 '19 at 15:09
  • @Jersey Glad to help. If my answer answers the question, please consider accepting it. – fractal Dec 20 '19 at 15:10
  • +1 You could also use the key node font for baselineskip, this allows you to avoid the duplication of \large. baselineskip/.style={node font={\baselineskip=#1}. –  Dec 20 '19 at 16:23
2

I don't see any need for the \par, but you can use /tikz/execute at begin node and /tikz/execute at end node:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}[
    every node/.style={fill=green, font=\large},
    execute at begin node={\baselineskip=5ex\relax},
    % execute at end node={\endgraf}% not needed, as far as I can see
    ]
  \node (N0) at (0,0) {Start};
  \node[right=of N0, text width=3.2cm, align=center] (N1)
    {Looooooooooong multi-line text.};
  \node[right=of N1, text width=3.2cm, align=center] (N2)
    {Another looooooooooong multi-line text.};
\end{tikzpicture}

\end{document}

enter image description here

I removed the unneeded remember picture, overlay, increased the 3cm to 3.2cm to avoid an overfull \hbox in the second node and increased your \baselineskip=2.5ex to \baselineskip=5ex in order to make its effect more visible. The \relax ensures that TeX doesn't try to expand tokens after the 5ex when reading the value assigned to \baselineskip.

frougon
  • 24,283
  • 1
  • 32
  • 55