根据文本长度垂直分割圆形节点

根据文本长度垂直分割圆形节点

我正在寻找允许我垂直分割圆形节点的解决方案,但分割线的位置将根据文本宽度决定。

我认为最近的解决方案可能类似于这个

我是乳胶初学者,以下是我的尝试:

\documentclass{minimal}
\usepackage{graphics}
\usepackage{tikz}
\usetikzlibrary{shapes,snakes,positioning}
\begin{document}

\begin{tikzpicture}
% this is approach from here: https://tex.stackexchange.com/a/186494/192768
% I don't like this solution because of rotation that is not intuitive for me.  
\node [circle split,draw,rotate=90, label={$1$}] (z){\rotatebox{-90}{Very long} \nodepart{lower} \rotatebox{-90}{b}};

% 2 This works when left and right are similar
\node[inner sep=2pt, right = of z.south, draw, circle, label={$2$}] (za) {Left \quad Right};
\draw (za.north) -- (za.south);
% 3 line cross text
\node[inner sep=2pt, right = of za, draw, circle, label={$3$}] (za2) {Left long text \quad Right};
\draw (za2.north) -- (za2.south);
% 4 line cross text
\node[inner sep=2pt, right = of za2, draw, circle, label={$4$}] (za3) {Left long text \quad Right};
\draw (za3.north east) -- (za3.south east);
% 5 this is ok but just because of text width of right part
\node[inner sep=2pt, below = of za3, draw, circle, label={$5$}, align=left] (za4) {Left long \\ text Long long \quad R};
\draw (za4.north east) -- (za4.south east);

\end{tikzpicture}

\end{document}

代码结果

答案1

欢迎!您可以使用path picture。您需要告诉样式split circle您在右侧放置的内容,以便它可以测量宽度并据此绘制垂直线。

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{positioning}
\begin{document}

\begin{tikzpicture}[split circle/.style={circle,draw,path picture={
 \pgfmathsetmacro{\mywidth}{width("#1")+6pt}
 \draw ([xshift=-\mywidth]path picture bounding box.north east) --
   ([xshift=-\mywidth]path picture bounding box.south east);
 }}]
 \node[split circle=Right] (A) {long text\quad Right};
 \node[split circle=pft,right=of A] (B) {long text\quad pft};
 \node[split circle=hibernate,right=of B] (C) {long text\quad hibernate};
\end{tikzpicture}
\end{document}

在此处输入图片描述

以下是样式采用两个参数的版本。

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{positioning}
\begin{document}

\begin{tikzpicture}[split circle/.style 2 args={circle,draw,path picture={
 \pgfmathsetmacro{\mywidth}{width("#2")+4pt+width("\quad")/2}
 \draw ([xshift=-\mywidth]path picture bounding box.north east) --
   ([xshift=-\mywidth]path picture bounding box.south east);
 },node contents={#1\quad #2}}]
 \node (A) [split circle={long text}{Right}];
 \node (B) [split circle={long text}{pft},right=of A];
 \node (C) [split circle={long text}{hibernate},right=of B];
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

我混合了回答经过薛定谔的猫类似问题的回复

得出:

\documentclass[tikz]{standalone}
% BEGIN section 1 
\usepackage{tikz}
\usetikzlibrary{calc, positioning,fit,decorations.pathreplacing}
% END section 1
\begin{document}
% BEGIN section 2
\begin{tikzpicture}[scale=1]
\tikzset{
    pics/circle vertically split/.style 2 args = {
       code = {
         \pgfmathsetmacro{\widthOne}{width("#1")+4pt}
         \pgfmathsetmacro{\widthTwo}{width("#2")+4pt}

         \node[text=green](-this_is_currcent_center){+};
         \node[xshift=-\widthOne/2] (-left) {#1};
         \node[xshift=\widthTwo/2] (-right) {#2};
         \node[fit=(-left)(-right),draw,circle,text=red](-shape) {+};
         \node(-splitline) at ($ (-left.east)!.5!(-right.west) $) {};
         \draw (-shape.north east -| -splitline.center) -- (-shape.south east -| -splitline.center);
       }
    }
}
\pic[inner sep = 1pt] (A) {circle vertically split={$Aaaaaa$}{$B$}};
\pic[inner sep = 1pt, right = of A-shape] (B) {circle vertically split={A}{$Bbbbb$}};

% this doesn't center correctly vertically :(
\pic[inner sep = 1pt, below = of A-shape.south] (D) {circle vertically split={$Aaaaaa$}{$B$}};
\pic[inner sep = 1pt, below = of B-shape.south] (E) {circle vertically split={$Aaaaaa$}{$B$}};

   \draw [decoration={brace,raise=4pt,mirror},
           decorate,
         ] (E-left.west) -- (E-left.east) node [pos=0.5,anchor=north,yshift=-4pt]{$brace$};
\end{tikzpicture}
% END section 2
\end{document}

产生的结果: 在此处输入图片描述

此解决方案允许分别为左节点和右节点添加括号。我在问题中忽略了这一点,试图使其尽可能简单。

这也存在一些缺陷 - 例如它不能正确对齐。

可以随意编辑或添加比这个更通用的新答案。

相关内容