I was wondering if there is a way to set the height of rectangle split parts. I had no luck finding something in the pgfmanual. (Using \phantom
seems just like a quickfix.)
Here is an example to illustrate my problem.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\tikzstyle{data}=[rectangle split,rectangle split parts=2,draw,text centered]
\begin{document}
\begin{tikzpicture}[node distance=2cm]
\node [data] (A) {data \nodepart{second} \phantom{null}};
\node [data, right of=A] (B) {data};
\node [data, right of=B] (C) {data \nodepart{second} null};
\end{tikzpicture}
\end{document}
Output
Best Answer
The following solution is a compromise between
\nodepart{second} \hphantom{null}
(or an extra macro) and the condition that even not-empty parts have an specified width.The style
data+
takes one mandatory argument and sets the dimension of empty parts to the dimension of its argument.In your example you would need
data+=null
. Of course, if the actual content of the second part of the last node changes, you would have to change the argument given todata+
(though this could be a macro too).Code
Output
Excursus:
-1ex
The definition of the
data+
style was previouslyThe OP rightly asks
PGF/TikZ has one special macro that is inserted for an empty node-part if
/pgf/rectangle split ignore empty parts
isfalse
(which seems to be the default contrary to the PGF manual), otherwise we wouldn’t even get a box.The name of this macro is
\pgf@lib@sh@rs@every@emptypart
(for short: empty-part macro).One would expect that PGF stores away the lengths given to
rectangle split empty part <width|height|depth>
keys and does not build this macro with the latest dimensions until it is needed. But this is not the case.Every time
rectangle split empty part <width|height|depth>
is used a rule of the given width, height or depth is created and added to the empty-part macro (all other length parameters of that rule are0pt
, meaning they are invisible (e.g.\strut
)).The problem arises that rules (even invisible ones) are getting stacked horizontally. Rules with a height or depth do not get stacked vertically so they don’t accumulate extra height/depth, but rules with a width (horizontal rules) accumulate.
But wait! We only used those keys once! Yes, but no.
As a matter of fact they are used once before, namely during the initialization.
The file
pgflibraryshapes.multipart.code.tex
reads on lines 370, 378 and 386:When we start we have a square box of
1ex × 1ex
. If we add a vertical rule of2ex
we get a box of1ex × 2ex
, but if we add a horizontal rule of2ex
we get a box of3ex × 1ex
.A picture worth than thousand words?
I constructed an example, where
the initial box is empty:
and the rules have actually a “width” (orthogonal to its “length”), i.e. a horizontal rule has a height (actually a height and a depth so that the middle of the line lies on the baseline), and a vertical rule has a width.
Not-MWE
rs width
is a short-cut forrectangular split empty parts width
, the same holds forrs height
andrs depth
.Output
The rules are:
width
): redheight
): greendepth
): blueIs there a better solution?
Two come to mind:
instead of subtracting hard-coded
1ex
we could subtract the current actual widthwhich would work quite okay as long as its content is not wider than
#1
.Overwriting the empty-part macro.
There is a undocumented key
rectangle split every empty part
that is not used once in PGF and TikZ. Its definition isWe cannot do
rectangle split every empty part={\phantom{null}}
because TikZ switched to a\nullfont
that swallows everything. (Have you ever tried to just write something in atikzpicture
environment?). This is the same reason, I usedcalc
’s\<dimen>of
macros, they escape this cleverly.We could fill this empty part macro with rules (not again!) overwriting any existing content, but then we could just use our old solution without
-1ex
by just removing any content.Code