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.

This question already has an answer here:

This is the code I have:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\tikz \node[rectangle split, rectangle split parts=2]
  {first\nodepart{second}second\linebreak{}third};
\end{document}

Second and third lines are glued to each other. When I'm adding text width=5em to the style of this node — everything works fine. How can I make this \linebreak work, without explicit specification of the node width? Thanks.

share|improve this question

migrated from stackoverflow.com Oct 10 '11 at 10:42

This question came from our site for professional and enthusiast programmers.

marked as duplicate by Jake Mar 16 at 13:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
@Jake I agree, thanks for pointing it out –  yegor256 Dec 31 '12 at 12:32
    

3 Answers 3

up vote 11 down vote accepted

As long as you set an alignment for the text, you can use \\ without needing a tabular environment.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\tikz \node[rectangle split,draw,rectangle split parts=2,align=center]
  {first\nodepart{second}second\\third};
\end{document}

output of code

share|improve this answer
    
This is a much nicer solution than the accepted answer. –  Andy Dec 28 '11 at 18:43

There following example works here:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\tikz \node[rectangle split,draw,double]
  {first
    \nodepart{second}
    second
    \nodepart{third}
 third
};
\end{document}

With \nodepart you don't need a linebreak.

share|improve this answer

You could use a simple tabular environment, so you can get a line break without specifying the width, further you can define alignment. For example, together with draw option to see the node parts:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\tikz \node[draw,rectangle split, rectangle split parts=2]
  {first\nodepart{second}
  \begin{tabular}{@{}c@{}}second\\third\end{tabular}};
\end{document}

multi line node

share|improve this answer

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