# Align two rectangle split horizontal nodes vertically

I'd like to be able to align vertically two or more rectangle split horizontal nodes such that the central vertical lines align. As far as I can make out, the coordinates for those lines aren't known until after the nodes have been created. This is as far as I have gotten, with the north west anchor of the bottom node aligning with the bottom of the center vertical line of the top node.

\documentclass{article}

\usepackage[]{geometry}
\usepackage{tikz}
\usepackage{xparse}
\usepackage{etoolbox}
\usepackage{varwidth}

\newsavebox{\leftbox}
\newsavebox{\rightbox}
\newcounter{blocknum}

\usetikzlibrary{calc,positioning,shapes.multipart}

%% Thanks to egreg, make lrbox global (requires etoolbox.sty):
\cslet{glrbox}\lrbox
\expandafter\patchcmd\csname glrbox\endcsname{\setbox}{\global\setbox}{}{}
\cslet{endglrbox}\endlrbox

\NewDocumentEnvironment{Recipe}{}{%
\begin{glrbox}{\leftbox}
\begin{varwidth}{0.45\textwidth}
}{%
\end{varwidth}%
\end{glrbox}%
%%% More...
\ifnum\theblocknum=0
\tikz[remember picture,overlay] {\node[name=block-\theblocknum,
draw,
rectangle split,
rectangle split parts=2,
rectangle split horizontal]
{\nodepart{one}\usebox{\leftbox}\nodepart{two}\usebox{\rightbox}};
\coordinate (putit-\theblocknum) at (block-\theblocknum.text split |- block-\theblocknum.two split south);
}
\else
\tikz[remember picture,overlay] {\node[name=block-\theblocknum,
draw,
anchor=north west,
rectangle split,
rectangle split parts=2,
rectangle split horizontal] at  (putit-\previous)
{\nodepart{one}\usebox{\leftbox}\nodepart{two}\usebox{\rightbox}};
\coordinate (putit-\theblocknum) at (block-\theblocknum.text split |- block-\theblocknum.two split south);
}
\fi
\xdef\previous{\theblocknum}
\stepcounter{blocknum}%
}

\NewDocumentCommand{\righttext}{}{%
\end{varwidth}%
\end{glrbox}%
\begin{glrbox}{\rightbox}
\begin{varwidth}{0.45\textwidth}
}

%\setmainfont{}

\begin{document}

\begin{Recipe}
Left\strut
\righttext
Right\\1\\2\\3\\4\strut
\end{Recipe}

\begin{Recipe}
Left which is longer\strut
\righttext
Right which is certainly quite long\\1\\2\\3\\4\strut
\end{Recipe}

\end{document}


text split or one split anchors works for me:

\documentclass[tikz,border=2mm]{standalone}

\usetikzlibrary{calc,positioning,shapes.multipart}

\begin{document}

\begin{tikzpicture}
\node[ draw, align=left,
rectangle split,
rectangle split parts=2,
rectangle split horizontal] (A)
{Left\strut \nodepart{two} Right\\1\\2\\3\\4\strut};

\node[ draw, align=left,
rectangle split,
rectangle split parts=2,
rectangle split horizontal,
below= -\pgflinewidth of A.one split south,
anchor=one split north
] (B)
{Left which is longer\strut \nodepart{two} Right which is certainly quite long\\1\\2\\3\\4\strut};
\end{tikzpicture}

\end{document}


This is not an attempt to solve the problem in the way you try, but just to tell you that you can get the desired (?) output with fit.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{calc,positioning,fit}
\begin{document}
\begin{tikzpicture}
\node[align=left] (L1) {Left};
\node[align=left,right=0pt of L1] (R1) {Right\\1\\2\\3\\4\strut};
\node[fit=(L1)(R1),draw,inner sep=0pt](fit1){};
\draw (fit1.north -| R1.west) -- (fit1.south -| R1.west) coordinate (aux1);
%
\node[align=left,below=0pt of aux1,anchor=north west] (R2) {Right which is certainly quite long\\1\\2\\3\\4\strut};
\node[align=left,left=0pt of R2] (L2) {Left which is longer};
\node[fit=(L2)(R2),draw,inner sep=0pt](fit2){};
\draw (fit2.north -| R2.west) -- (fit2.south -| R2.west) coordinate (aux2);
\end{tikzpicture}
\end{document}


You seem to be very good at defining new environments, so I did not even try to do this here.

• Wow. I never cease to be amazed with what fit can do -- nice job! I'll play with this... – sgmoye Nov 17 '18 at 21:05
• @sgmoye I guess a purist might say you do not even need TikZ for that, rather that this can be done using a simple tabular. But I would not now how to do that properly, so let's wait for a proficient purist.;-) – user121799 Nov 17 '18 at 21:11
• Yes, a tabular might be possible, though, given the data, such a tabular might end up being large, unwieldy and difficult to maintain -- fragile. Keeping the pairs of data distinct in separate environments is, to my mind, cleaner and the preferred way to go. Still, I'll experiment... – sgmoye Nov 17 '18 at 21:23