Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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!

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}

\tikzset{
  mynode/.style={
    draw
  , align=center
  , execute at begin node=\setlength{\baselineskip}{2em}
  }
}

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

\end{document}

This produces:

Node breaks

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

share|improve this question
    
Remark: it might be better to specify vertical distances in terms of ex's, not em's. –  mbork Aug 5 '11 at 18:03

1 Answer 1

up vote 2 down vote accepted

What about this?

\setlength{\baselineskip}{16pt}

or

\baselineskip=16pt

(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".

share|improve this answer
1  
length macros need \ (aka escape character) but counter macros do not. I also did the same mistake often in the past. :-) –  xport Aug 5 '11 at 18:43
2  
@xport: This is because \baselineskip is a length defined by TeX itself. On the other hand if you create a counter by \newcounter{name} (a LaTeX command) this actually to the TeX \newcounter\c@name plus initializing plus creating the \thename macro. –  Caramdir Aug 5 '11 at 19:42
    
+2 @Caramdir: OK. thanks. :-) –  xport Aug 5 '11 at 20:25
    
xport: thanks for correcting me! Caramdir: thanks for the explanation! –  mbork Aug 5 '11 at 21:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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