我想将 TikZ 节点拆分为左右两部分,就像circle split
拆分为上半部分和下半部分一样,例如
\node [circle split,draw] (x){$a$ \nodepart{lower} $b$}
是否有垂直等效项,例如
\node [circle split vertical,draw] (x){$a$ \nodepart{right} $b$}
?
这是一个分裂节点的示例水平,但我希望分割垂直的:
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{shapes,snakes}
\begin{document}
\begin{tikzpicture}
\node [circle split,draw] (z){$a$ \nodepart{lower} $b$};
\end{tikzpicture}
\end{document}
答案1
\documentclass{minimal}
\usepackage{graphics}
\usepackage{tikz}
\usetikzlibrary{shapes,snakes}
\begin{document}
\begin{tikzpicture}
\node [circle split,draw,rotate=90] (z){\rotatebox{-90}{$a$} \nodepart{lower} \rotatebox{-90}{$b$}};
\end{tikzpicture}
\end{document}
答案2
此解决方案使用 PGF 3.0.0 的pic
新功能,定义一个名为的新 pic 元素,node vertically split
该元素接收两个参数,即左侧和右侧部分的内容。它还为 pic 的各个部分定义名称,以便以后添加不同类型的连接,如示例中所示。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{
pics/circle vertically split/.style 2 args = {
code = {
\node[inner sep=3pt,left] (-left) {#1};
\node[inner sep=3pt,right] (-right) {#2};
\path let
\p1 = ($(-left.north west) - (-left.east)$),
\p2 = ($(-right.west) - (-right.south east)$),
\n1 = {max(veclen(\p1), veclen(\p2))*2}
in node[minimum size=\n1, circle, draw] (-shape) at (0,0) {};
\draw (-shape.north) -- (-shape.south);
}
}
}
\begin{document}
\begin{tikzpicture}
\draw (0,0) pic (A) {circle vertically split={$a$}{$b$}}
(2,2) pic (B) {circle vertically split={Hello}{World}}
(2,-1) pic (C) {circle vertically split={Hello}{$b$}};
\draw[->, blue] (A-shape) -- (B-shape);
\draw[blue, dotted] (C-shape.north east) -- (B-shape.south east);
\draw[->, red] (A-right) to[out=0,in=90] (C-right.north);
\end{tikzpicture}
\end{document}
结果:
答案3
PSTricks 解决方案:
\documentclass{article}
\usepackage{pstricks}
\def\size{2 }
\begin{document}
\begin{pspicture}(-\size,-\size)(\size,\size)
\pswedge{\size}{90}{270}
\rput(!-\size 2 div 0){\Huge $a$}
\pswedge{\size}{270}{90}
\rput(!\size 2 div 0){\Huge $b$}
\end{pspicture}
\end{document}