3

I've tried to apply the answer in Minimum height in split rectangle (with many thanks to Alain Matthes) using their defined mystrut.

I modified their code to have two lines in each nodepart

in the section of their code after % Split Rectangle, when I add \centerline{......} \centerline{........} after \nodepart{one} \mystrut, it will only modify the height of the box around the first line instead of the entire \nodepart{one}, how can I fix it?.

The modified code:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}
\def\mystrut{\vrule height 1.5cm depth 1.5cm width 0pt} 

\begin{document}    

\begin{tikzpicture}[auto,
rect/.style={
    rectangle split,
    rectangle split parts=4,
    draw=black,
    rounded corners,
    text width = 3cm
}]  


% Split Rectangle
\node [rect] {
  \mystrut  \centerline{First} \\ \centerline{Item}
    \nodepart{two}\mystrut \centerline{Second} \\ \centerline{Item}
    \nodepart{three} \centerline{$\vdots$}
    \nodepart{four} \mystrut \centerline{Last} \\ \centerline{Item}
    };

\end{tikzpicture}
\end{document}    

Result:

enter image description here

0

1 Answer 1

3

You need to put a \mystrut on each line you want the space added to, including the second line of each part, if applicable.

Better than using \centerline, which should be used very rarely in LaTeX, use the align or rectangle split parts align styles.

Do you want something like this?

spacier boxes

If so, I think it is more straightforward to play with inner xsep and inner ysep.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\begin{document}
\begin{tikzpicture}[auto,
  rect/.style={
    rectangle split,
    rectangle split parts=4,
    draw=black,
    rounded corners,
    rectangle split part align=center,
    align=center,
    inner ysep=12mm,
    inner xsep=10mm,
  }]
  % Split Rectangle
  \node [rect] {%
    First\\Item
    \nodepart{two}Second\\Item
    \nodepart{three}$\vdots$
    \nodepart{four}Last\\Item%
  };
\end{tikzpicture}
\end{document}

EDIT

If you want something more like the following:

variable heights

then you might want to use \mystrut, but redefine it to take arguments. In the following, the first argument is the height and the second the depth. For two-line nodes, we set the second argument to zero on the first line and the first argument to zero on the second.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\newcommand*\mystrut[2]{\vrule height #1 depth #2 width 0pt}
\begin{document}
\begin{tikzpicture}[auto,
  rect/.style={
    rectangle split,
    rectangle split parts=4,
    draw=black,
    rounded corners,
    rectangle split part align=center,
    align=center,
%     inner ysep=12mm,
    inner xsep=10mm,
  }]
  % Split Rectangle
  \node [rect] {%
    \mystrut{15mm}{0pt}First\\\mystrut{0pt}{15mm}Item
    \nodepart{two}\mystrut{10mm}{0pt}Second\\\mystrut{0pt}{10mm}Item
    \nodepart{three}\mystrut{5mm}{5mm}$\vdots$
    \nodepart{four}\mystrut{25mm}{0pt}Last\\\mystrut{0pt}{25mm}Item%
  };
\end{tikzpicture}
\end{document}
10
  • But how can I control the height for each nodepart? Aug 17, 2017 at 11:33
  • You mean you want different heights for each part? For example, 2cm for the first, 3 for the second, 1 for the third and 5 for the fourth or something?
    – cfr
    Aug 17, 2017 at 12:49
  • @FacebFaceb Please see edit above. I would use \mystrut in that case, but redefining it to give you the flexibility you need for multiline nodes of different heights.
    – cfr
    Aug 17, 2017 at 12:57
  • Thanks! What are the meanings of the two arguments of \mystrut, because for example in \nodepart{two} you put 10mm as first argument for the first line and 10mm as second argument for the second line. I cannot tag you btw (as in using @cfr) Aug 17, 2017 at 13:12
  • 1
    @FacebFaceb How do you want them spaced? I'd not use \mystrut on the second or third line and just add it on the first and fourth. That way, the text lines stay together. But it depends what you want.
    – cfr
    Aug 18, 2017 at 22:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .