[Tex/LaTex] Change line spacing inside a node in TikZ


Inside a TikZ node, one can force line breaks using \\ providing the align option of the node is set.

I would like to increase the line spacing inside a node. This can be done in the usual way with the optional parameter of \\, e.g. \\[1em]. Doing this for every line break is tedious though. Is there a way to increase the break globally, so that any \\ inside a node acts as \\[1em]?

EDIT: Almost there!




  , align=center
  , execute at begin node=\setlength{\baselineskip}{2em}

  \node[mynode] {
    this \\
    is \\
    \tikz \node[mynode] {a \\ break};


This produces:

Node breaks

The remaining question is how to place a 2em break before the inner node.

Best Answer

What about this?




(If it doesn't work, try ending your node text with an explicit \par.)

Now as for the second part: this is not only non-trivial, but also not well-defined. As the name suggests, \baselineskip is the distance between the baselines of consecutive lines of text (or hboxes, if you prefer). In the case of the "inner" tikz node, there's the question: where its baseline is located? This is configurable by the tikz option baseline (this was hard to guess, right;)?), but if you set it higher, then - if you add another line or whatever below - the distance there will be to small.

Probably the best answer to your problem are the \lineskip and \lineskiplimit parameters. Actually (well, AFAIR, since I've got my copy of The TeXbook at my office), the rule is (more or less) as follows:

if TeX puts two boxes on a vertical list, it puts glue between them so the distance between their baselines equals \baselineskip. But, if the distance between the bottom of the upper box and the top of the lower one would be smaller than \lineskiplimit, the glue inserted equals \lineskip.

Therefore you might want to set it up the following way:

\baselineskip=<the distance you want between the baselines>
\lineskiplimit=<the threshold distance>
\lineskip=<the distance you want between the boxes (not their baselines!) if they are close to each other>

where "close to each other" means "closer than the threshold".