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

1 Answers1

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}
cfr
  • 198,882
  • But how can I control the height for each nodepart? – Faceb Faceb Aug 17 '17 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 '17 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 '17 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) – Faceb Faceb Aug 17 '17 at 13:12
  • And what will the arguments be ff a \nodepart has more than 2 lines? – Faceb Faceb Aug 17 '17 at 14:14
  • @FacebFaceb You just use \mystrut with whatever arguments you need on however many lines you need. It is only affecting that particular line. – cfr Aug 17 '17 at 15:59
  • 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) (my comment from a few hours ago) – Faceb Faceb Aug 17 '17 at 16:32
  • @FacebFaceb The first gives the height of the rule and the second the depth. If the lines should be together in the middle, then you want zero (additional) depth for the first line and zero (additional) height for the second. You can't get auto-completion on my tag if you're commenting on a post I wrote as I'm pinged automatically. – cfr Aug 17 '17 at 22:17
  • But could you give an example with \mystrut for a \nodepart that has 4 lines? – Faceb Faceb Aug 18 '17 at 18:53
  • 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 '17 at 22:45