我希望能够垂直对齐两个或多个rectangle split horizontal
节点,使中心垂直线对齐。据我所知,直到后节点已创建。这是我目前得到的结果,north west
底部节点的锚点与顶部节点中心垂直线的底部对齐。
\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}
答案1
text split
或者one split
锚点对我有用:
\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}
答案2
这并不是尝试以您尝试的方式解决问题,而只是告诉您可以使用获得所需的(?)输出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}
您似乎非常擅长定义新环境,所以我甚至没有尝试在这里这样做。