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.

Consider the following code:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes,positioning,fit}

\begin{document}

\begin{tikzpicture}
  \node[draw, rectangle split, rectangle split parts=2]{
    x y%
    \nodepart{two}{%
      \tikz \node[draw, rectangle] {bubble \\ gum};%
    }
  };
\end{tikzpicture}

\vspace{2em}

\begin{tikzpicture}
  \node[align=center, rectangle split part align={center, left}, draw, rectangle split, rectangle split parts=2]{
    x y%
    \nodepart{two}{%
      \tikz \node[draw, rectangle] {bubble \\ gum};%
    }
  };
\end{tikzpicture}

\vspace{2em}

\begin{tikzpicture}
  \node[align=left,draw, rectangle split, rectangle split parts=2]{
    x y%
    \nodepart{two}{%
      \tikz \node[draw, rectangle] {bubble \\ gum};%
    }
  };
\end{tikzpicture}

\end{document}

It produces the following:

Node alignment problem

In the first example, the inner node is correctly nested in the center of the outer one. However, line breaks in the inner node content are ignored.

Adding align=center or align=left to the options of the outer node results in the line breaks being respected, but the inner node is not centered any more. I don't understand why this is happening.

How can I get the desired behaviour: line breaks are displayed and the inner node is centered within the outer one?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Like this ?

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes,positioning,fit}

\begin{document}

\begin{tikzpicture}
  \node[rectangle split part align={center, left}, draw, rectangle split, rectangle split parts=2]{
    x y%
    \nodepart{two}{%
      \tikz \node[align=center, draw, rectangle] {bubble \\ gum};%
    }
  };
\end{tikzpicture}

\vspace{2em}

\begin{tikzpicture}
  \node[draw, rectangle split, rectangle split parts=2]{
    x y%
    \nodepart{two}{%
      \tikz \node[align=left,draw, rectangle] {bubble \\ gum};%
    }
  };
\end{tikzpicture}

\end{document} 

enter image description here

share|improve this answer

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.