# Line break in multipart rectangle node with align specification

I'd like to ask how I can add a line break in a multipart rectangle node.

Code that I've written should work but it is not. Can you tell me what I have done wrong, or how can I tune it to make it work.

\tikzstyle{umlclass}=[
draw=black,
fill=yellow!16,
rectangle split,
rectangle split parts = 3,
rectangle split part align={center,left,left},
execute at begin node = \ttfamily,
]
\node[umlclass]{
<<interface>>\\
class
\nodepart{second}
+attribute
};

-
Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  egreg Feb 1 '13 at 17:33
I would consider using the tikz-uml package: is not available on CTAN, but it could be of help for your purpose. –  Claudio Fiandrino Feb 1 '13 at 17:53
no it's not, there is lot of sheity thinks. Most importat is that it wont iplements shapes and styles. –  wikingun Feb 1 '13 at 18:00
@wikingun: actually I don't know anything about uml, but I've looked at the code and, from a TikZ point of view, you can define your own styles via \tikzumlset. –  Claudio Fiandrino Feb 1 '13 at 18:09

You could simply use a \parbox. You still could use \centering for the alignment, if desired. Furthermore it's recommended to use \tikzset instead of \tikzstyle.

\documentclass[10pt]{book}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\tikzset{umlclass/.style={
draw=black,
fill=yellow!16,
rectangle split,
rectangle split parts = 3,
rectangle split part align={center,left,left},
execute at begin node = \ttfamily,
}}
\begin{document}
\begin{tikzpicture}

\node[umlclass]{
\parbox{2.4cm}{\centering
<<interface>>\\
class}
\nodepart{second}
+attribute
};
\end{tikzpicture}
\end{document}


The very good comment of egreg, to use a tabular to not need to know the width:

\node[umlclass]{
\begin{tabular}{@{}c@{}}
<<interface>>\\
class
\end{tabular}
\nodepart{second}
+attribute
};


-
Or a tabular, that avoids the need to guess the width. –  egreg Feb 1 '13 at 17:45
stefab do you see that class is LEFT aligned? –  wikingun Feb 1 '13 at 17:46
Is not what i wanted, but it is also helpful –  wikingun Feb 1 '13 at 17:49
@egreg or I just handrite it ? –  wikingun Feb 1 '13 at 17:50
I've taken the liberty of improving the tabular; defining \newcommand{\splitpart}[1]{\begin{tabular}{@{}c@{}}#1\end{tabular}} may be even better. –  egreg Feb 1 '13 at 17:58

You have to supply align=center to the general node options, as the first node part isn't treated like the others. The rectangle split part align option does apply to it, but only affects the box that uses the align option internally (which is also the reason \\ hasn’t the expected effect).

That means that one need to specify align=center and rectangle split part align={center,…}

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart,positioning}
\tikzset{
umlclass/.style={
draw=black,fill=yellow!16,rectangle split,rectangle split parts = 3,font = \ttfamily},
umlclass -c/.style={
umlclass,align=center,rectangle split part align={left}},         % = left,   left, left
umlclass -r/.style={
umlclass,align=right, rectangle split part align={left}},         % = left,   left, left
umlclass +/.style={
umlclass,align=center, rectangle split part align={center,left}}} % = center, left, left
\newcommand*{\umlclasscontent}{<<interface>>\\class\nodepart{second}very long attribute\nodepart{third}method()}
\begin{document}
\begin{tikzpicture}
\node[umlclass -c]           {\umlclasscontent};
\node[umlclass -r] at (0,-3) {\umlclasscontent};
\node[umlclass +]  at (0,-6) {\umlclasscontent};
\end{tikzpicture}
\end{document}

-
THX, This is the solution that I looking for. –  wikingun Feb 1 '13 at 18:21
or is not... try to add two atributes... –  wikingun Feb 1 '13 at 18:26
@wikingun: Yes: It works flawlessly –  Jake Feb 1 '13 at 19:09
@Jake I have edited your answer because the align=center part is the right solution here (+1) but rectangle split part align does (kind of) apply to the first text box, too. –  Qrrbrbirlbel Feb 2 '13 at 0:00
@Qrrbrbirlbel: Excellent, thanks! –  Jake Feb 2 '13 at 11:28