2

I am not able to fix the height of both parts of a (vertical) two-part rectangle to the same height. As a result, the arrow to the box on the right is not aligned with the middle line. I have been reading but have not been able to resolve it. Is there a way? Here is my MWE:

\documentclass[margin=3mm]{standalone}

\usepackage{tikz}


\usetikzlibrary{
arrows %
,positioning %
,shapes%
,shapes.multipart%
}

\begin{document}

\begin{tikzpicture}

\node[rectangle split, draw, rectangle split, rectangle split parts=2, align=center] (box1) {Application \nodepart[text width=3cm]{two} GFS Client};
\node[rectangle,draw, align=center, right=3.5cm of box1] (box2) {Master};

\draw[->] (box1) -- (box2) node[midway, above] ( ) {Get chunk location};

\end{tikzpicture}


\end{document}

Here is what comes out:

enter image description here

1

In this particular case, both parts of multipart rectangle don't have similar height, because Application has a decendant part (p) which is not present in GFS Client. You can force them to be equal inserting a \strut command in both texts.

\documentclass[margin=3mm]{standalone}
\usepackage{tikz}

\usetikzlibrary{
arrows %
,positioning %
,shapes%
,shapes.multipart%
}

\begin{document}

\begin{tikzpicture}

\node[rectangle split, draw, rectangle split, rectangle split parts=2, align=center] (box1) {Application\strut \nodepart[text width=3cm]{two} GFS Client\strut};
\node[rectangle,draw, align=center, right=3.5cm of box1] (box2) {Master};

\draw[->] (box1) -- (box2) node[midway, above] ( ) {Get chunk location};

\end{tikzpicture}

\end{document}

enter image description here

  • Thank you for this -- I now learned another way to do this. – ozsu Aug 4 '18 at 18:57
  • @ozsu I was actually also thinking about using \strut but was deciding against it because this wastes some space. That's why I was using a \vphantom{p}.... – user121799 Aug 4 '18 at 19:08
3

I would actually not try to make the node parts equally high (even though this can be done), but just let the arrow start at the text split.

\documentclass[margin=3mm]{standalone}

\usepackage{tikz}


\usetikzlibrary{
arrows %
,positioning %
,shapes%
,shapes.multipart%
}

\begin{document}

\begin{tikzpicture}

\node[rectangle split, draw, rectangle split, rectangle split parts=2, align=center] (box1) {Application \nodepart[text width=3cm]{two} GFS Client};
\node[rectangle,draw, align=center, right=3.5cm of box1.text split east] (box2) {Master};

\draw[->] (box1.text split east) -- (box2) node[midway, above] ( ) {Get chunk location};

\end{tikzpicture}
\end{document}

enter image description here

But if you really need the heights to coincide, just call a phantom.

\documentclass[margin=3mm]{standalone}

\usepackage{tikz}


\usetikzlibrary{
arrows %
,positioning %
,shapes%
,shapes.multipart%
}

\begin{document}

\begin{tikzpicture}

\node[rectangle split, draw, rectangle split, rectangle split parts=2,
align=center] (box1) {Application \nodepart[text width=3cm]{two} \vphantom{p}GFS Client};
\node[rectangle,draw, align=center, right=3.5cm of box1] (box2) {Master};

\draw[->] (box1) -- (box2) node[midway, above] ( ) {Get chunk location};

\end{tikzpicture}
\end{document}

enter image description here

  • Wonderful, many thanks. I did not know either option and am very glad to learn. – ozsu Aug 3 '18 at 23:23
  • 1
    defining text width for node part at vertical split rectangles has no sense. in it all parts have equal width ... – Zarko Aug 3 '18 at 23:23
  • @Zarko I agree, thanks, didn't look carefully. On the other hand, it really does not hurt here either. – user121799 Aug 3 '18 at 23:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.