TikZ - 圆形分割忽略空部分

TikZ - 圆形分割忽略空部分

这个问题已经在TikZ:去除圆形分割、矩形分割等的内线。,但没有回答圈子的问题:

如何删除图片中的分割线

every node/.style={circle split}

没有这样的键,circle split ignore empty parts而且我在手册中也没有找到任何东西。

有什么解决方法吗?

答案1

具有新形状

\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{shapes,calc}
\makeatletter
\pgfdeclareshape{new circle split}
{
  %
  % Node parts
  %
  \nodeparts{text,lower}

  %
  % Anchors
  %
  \savedanchor\centerpoint{%
    \pgf@x=.5\wd\pgfnodeparttextbox%
    \pgfmathsetlength{\pgf@y}{\pgfkeysvalueof{/pgf/inner ysep}}%
    \pgf@y=-\pgf@y%
    \advance\pgf@y by-\dp\pgfnodeparttextbox%
    \advance\pgf@y by-.5\pgflinewidth%
  }%
  \savedanchor\loweranchor{%
    \pgf@x=-.5\wd\pgfnodepartlowerbox%
    \advance\pgf@x by.5\wd\pgfnodeparttextbox%
    \pgfmathsetlength{\pgf@y}{\pgfkeysvalueof{/pgf/inner ysep}}%
    \pgf@y=-2\pgf@y%
    \advance\pgf@y by-\ht\pgfnodepartlowerbox%
    \advance\pgf@y by-.5\pgflinewidth%
    \advance\pgf@y by-\dp\pgfnodeparttextbox%
    \advance\pgf@y by-.5\pgflinewidth%
  }

  \saveddimen\radius{%
    % 
    % Caculate ``height radius''
    %
    %\pgf@ya=.5\ht\pgfnodeparttextbox%
%    \advance\pgf@ya by.5\dp\pgfnodeparttextbox%
%    \advance\pgf@ya by.5\ht\pgfnodepartlowerbox%
%    \advance\pgf@ya by.5\dp\pgfnodepartlowerbox%
%    \advance\pgf@ya by.5\pgflinewidth%
        %
        % MW: Suggested correction for above calculation:   Use the tallest box * 2.
        %
        \pgf@ya=.5\ht\pgfnodeparttextbox%
        \advance\pgf@ya by.5\dp\pgfnodeparttextbox%
        \pgf@yb=.5\ht\pgfnodepartlowerbox%
        \advance\pgf@yb by.5\dp\pgfnodepartlowerbox%
        \ifdim\pgf@ya>\pgf@yb\relax%
            \[email protected]\pgf@ya\relax%
        \else%
            \[email protected]\pgf@yb\relax%
        \fi%
        \advance\pgf@ya by.5\pgflinewidth%
    \pgfmathsetlength\pgf@yb{\pgfkeysvalueof{/pgf/inner ysep}}%
    \advance\pgf@ya by2\pgf@yb%
    % 
    % Caculate ``width radius''
    % 
    \pgf@xa=.5\wd\pgfnodeparttextbox%
    \ifdim\pgf@xa<.5\wd\pgfnodepartlowerbox%
      \pgf@xa=.5\wd\pgfnodepartlowerbox%
    \fi%
    \pgfmathsetlength\pgf@xb{\pgfkeysvalueof{/pgf/inner xsep}}%
    \advance\pgf@xa by\pgf@xb%
    % 
    % Calculate length of radius vector:
    % 
    \pgf@process{\pgfpointnormalised{\pgfqpoint{\pgf@xa}{\pgf@ya}}}%
    \ifdim\pgf@x>\pgf@y%
        \c@pgf@counta=\pgf@x%
        \ifnum\c@pgf@counta=0\relax%
        \else%
          \divide\c@pgf@counta by 255\relax%
          \pgf@xa=16\pgf@xa\relax%
          \divide\pgf@xa by\c@pgf@counta%
          \pgf@xa=16\pgf@xa\relax%
        \fi%
      \else%
        \c@pgf@counta=\pgf@y%
        \ifnum\c@pgf@counta=0\relax%
        \else%
          \divide\c@pgf@counta by 255\relax%
          \pgf@ya=16\pgf@ya\relax%
          \divide\pgf@ya by\c@pgf@counta%
          \pgf@xa=16\pgf@ya\relax%
        \fi%
    \fi%
    \pgf@x=\pgf@xa%
    % 
    % If necessary, adjust radius so that the size requirements are
    % met: 
    % 
    \pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/minimum width}}%  
    \pgfmathsetlength{\pgf@yb}{\pgfkeysvalueof{/pgf/minimum height}}%  
    \ifdim\pgf@x<.5\pgf@xb%
        \pgf@x=.5\pgf@xb%
    \fi%
    \ifdim\pgf@x<.5\pgf@yb%
        \pgf@x=.5\pgf@yb%
    \fi%
    % 
    % Now, add larger of outer sepearations.
    % 
    \pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/outer xsep}}%  
    \pgfmathsetlength{\pgf@yb}{\pgfkeysvalueof{/pgf/outer ysep}}%  
    \ifdim\pgf@xb<\pgf@yb%
      \advance\pgf@x by\pgf@yb%
    \else%
      \advance\pgf@x by\pgf@xb%
    \fi%
  }

  %
  % Anchors
  % 
  \inheritanchorborder[from=circle]
  \inheritanchor[from=circle]{north}
  \inheritanchor[from=circle]{north west}
  \inheritanchor[from=circle]{north east}
  \inheritanchor[from=circle]{center}
  \inheritanchor[from=circle]{west}
  \inheritanchor[from=circle]{east}
  \inheritanchor[from=circle]{mid}
  \inheritanchor[from=circle]{mid west}
  \inheritanchor[from=circle]{mid east}
  \inheritanchor[from=circle]{base}
  \inheritanchor[from=circle]{base west}
  \inheritanchor[from=circle]{base east}
  \inheritanchor[from=circle]{south}
  \inheritanchor[from=circle]{south west}
  \inheritanchor[from=circle]{south east}
  \anchor{lower}{\loweranchor}

  %
  % Background path
  %
  \inheritbackgroundpath[from=circle]
  \beforebackgroundpath{
    \pgfutil@tempdima=\radius%
    \pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/outer xsep}}%  
    \pgfmathsetlength{\pgf@yb}{\pgfkeysvalueof{/pgf/outer ysep}}%  
    \ifdim\pgf@xb<\pgf@yb%
      \advance\pgfutil@tempdima by-\pgf@yb%
    \else%
      \advance\pgfutil@tempdima by-\pgf@xb%
    \fi%
    \advance\pgfutil@tempdima by-.5\pgflinewidth%  
    \pgfsetshortenstart{0pt}%
    \pgfsetshortenend{0pt}%
    \pgfsetarrows{-}%  
  %  \pgfpathmoveto{\pgfpointadd{\centerpoint}{\pgfqpoint{-1\pgfutil@tempdima}{0pt}}}%
  %  \pgfpathlineto{\pgfpointadd{\centerpoint}{\pgfqpoint{\pgfutil@tempdima}{0pt}}}%
    \pgfusepath{stroke}%
  }
}


\begin{document}

\begin{tikzpicture}
  \node [new circle split,
         draw,
         minimum width=4cm,
         append after command={%
                   }]
  {top
    \nodepart{lower}
    below
  };
\end{tikzpicture}

\end{document} 

在此处输入图片描述

答案2

我认为还有另一种方法。你仍然可以实现相同的效果,但对象将不再是节点multipart

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\node (A) [shape=circle,draw,matrix] at (0,0) {\node {Hello};\\ \node{World};\\};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容