PSTricks 中的重叠标签

PSTricks 中的重叠标签

考虑以下示例。

\documentclass{beamer}

\usepackage[locale = DE]{siunitx}
\usepackage{xfp}
\usepackage{etoolbox}
\usepackage{pstricks-add}
\usepackage{tikz}

\psset{dimen = m}

% data
\def\bredde{4.5}
\def\start{0}
\def\eleverNul{4}
\def\eleverEn{2}
\def\eleverTo{5}
\def\eleverTre{7}
\def\eleverFire{5}
\def\eleverFem{3}
% beregninger
\newcommand*\eleverSumNul{\eleverNul}
\newcommand*\eleverSumEn{\fpeval{\eleverSumNul+\eleverEn}}
\newcommand*\eleverSumTo{\fpeval{\eleverSumEn+\eleverTo}}
\newcommand*\eleverSumTre{\fpeval{\eleverSumTo+\eleverTre}}
\newcommand*\eleverSumFire{\fpeval{\eleverSumTre+\eleverFire}}
\newcommand*\eleverSumFem{\fpeval{\eleverSumFire+\eleverFem}}
\newcommand*\eleverTotal{\fpeval{\eleverSumFem}}
\def\andelB[#1]#2#3#4{%
  \pswedge[fillstyle = solid, fillcolor = #1]%
     {\radius}{\fpeval{round(#2/\eleverTotal*360,9)}}{\fpeval{round(#3/\eleverTotal*360,9)}}
  \ifstrequal{#1}{black}%
    {\psarc[linecolor = white]%
       (0,0){0.5}{\fpeval{round(#2/\eleverTotal*360,9)}}{\fpeval{round(#3/\eleverTotal*360,9)}}
     \uput{8pt}[\fpeval{round((#2+#3)/\eleverTotal*180,9)}]%
       (0,0){\textcolor{white}{\footnotesize\SI{\fpeval{round((#3-#2)/\eleverTotal*360)}}{\degree}}}}
    {\psarc%
       (0,0){0.5}{\fpeval{round(#2/\eleverTotal*360,9)}}{\fpeval{round(#3/\eleverTotal*360,9)}}
     \uput{8pt}[\fpeval{round((#2+#3)/\eleverTotal*180,9)}]%
       (0,0){\footnotesize\SI{\fpeval{round((#3-#2)/\eleverTotal*360)}}{\degree}}}%
}


\begin{document}

\begin{frame}{Opgave~$7$}
\begin{center}
\psset{
  unit = 0.4,
  linejoin = 1
}
\def\radius{5}
  \begin{pspicture}(\fpeval{-(\radius+0.1)},\fpeval{-(\radius+0.1)})%
                   (\fpeval{+(\radius+0.1)},\fpeval{+(\radius+0.1)})
    \visible<4->{%
      \pscircle(0,0){\radius}
      \multido{\r = 0+\fpeval{round(360/\eleverTotal,9)}}{\eleverTotal}{%
      \psRelLine[angle = \r](0,0)(\fpeval{\radius+0.1},0){1}{EndNode}
      \psRelLine[angle = \r, linecolor = white, linewidth = 2\pslinewidth]%
        (0,0)(\fpeval{\radius-0.1},0){1}{EndNode}}}
    \visible<5->{\andelB[yellow!70]{\start}{\eleverSumNul}}
    \visible<6->{\andelB[red!70]{\eleverSumNul}{\eleverSumEn}}
    \visible<7->{\andelB[green!80]{\eleverSumEn}{\eleverSumTo}}
    \visible<8->{\andelB[orange!80]{\eleverSumTo}{\eleverSumTre}}
    \visible<9->{\andelB[blue!70!white]{\eleverSumTre}{\eleverSumFire}}
    \visible<10->{\andelB[black]{\eleverSumFire}{\eleverSumFem}}
  \end{pspicture}
\end{center}
\end{frame}

\end{document}

截屏

问题

可以看出,28°标签没有印在绿色楔形物的“顶部”。 (当然,其他标签也是如此。)

如何确保标签始终打印在“顶部”?

答案1

只需修改一些参数:

    \documentclass{beamer}

    \usepackage[locale = DE]{siunitx}
    \usepackage{xfp}
    \usepackage{etoolbox}
    \usepackage{pstricks-add}
    \usepackage{tikz}

    \psset{dimen = m}

    % data
    \def\bredde{4.5}
    \def\start{0}
    \def\eleverNul{4}
    \def\eleverEn{2}
    \def\eleverTo{5}
    \def\eleverTre{7}
    \def\eleverFire{5}
    \def\eleverFem{3}
    % beregninger
    \newcommand*\eleverSumNul{\eleverNul}
    \newcommand*\eleverSumEn{\fpeval{\eleverSumNul+\eleverEn}}
    \newcommand*\eleverSumTo{\fpeval{\eleverSumEn+\eleverTo}}
    \newcommand*\eleverSumTre{\fpeval{\eleverSumTo+\eleverTre}}
    \newcommand*\eleverSumFire{\fpeval{\eleverSumTre+\eleverFire}}
    \newcommand*\eleverSumFem{\fpeval{\eleverSumFire+\eleverFem}}
    \newcommand*\eleverTotal{\fpeval{\eleverSumFem}}
    \def\andelB[#1]#2#3#4{%
      \pswedge[fillstyle = solid, fillcolor = #1]%
         {\radius}{\fpeval{round(#2/\eleverTotal*360,9)}}{\fpeval{round(#3/\eleverTotal*360,9)}}
      \ifstrequal{#1}{black}%
        {\psarc[linecolor = white]%
           (0,0){1.5}{\fpeval{round(#2/\eleverTotal*360,9)}}{\fpeval{round(#3/\eleverTotal*360,9)}}%
         \uput{2}[\fpeval{round((#2+#3)/\eleverTotal*180,9)}]%8pt
           (0,0){\textcolor{white}{\footnotesize\SI{\fpeval{round((#3-#2)/\eleverTotal*360)}}{\degree}}}}
        {\psarc%
           (0,0){1.5}{\fpeval{round(#2/\eleverTotal*360,9)}}{\fpeval{round(#3/\eleverTotal*360,9)}}%
    %\def\r{}
         \uput{2}[\fpeval{round((#2+#3)/\eleverTotal*180,9)}]%
           (0,0){\footnotesize\SI{\fpeval{round((#3-#2)/\eleverTotal*360)}}{\degree}}}%
    }


    \begin{document}

    \begin{frame}{Opgave~$7$}
    \begin{center}
    \psset{
      unit = 0.4,
      linejoin = 1
    }
    \def\radius{5}
      \begin{pspicture}(\fpeval{-(\radius+0.1)},\fpeval{-(\radius+0.1)})%
                       (\fpeval{+(\radius+0.1)},\fpeval{+(\radius+0.1)})
        \visible<4->{%
          \pscircle(0,0){\radius}
          \multido{\r = 0+\fpeval{round(360/\eleverTotal,9)}}{\eleverTotal}{%
          \psRelLine[angle = \r](0,0)(\fpeval{\radius+0.1},0){1}{EndNode}
          \psRelLine[angle = \r, linecolor = white, linewidth = 2\pslinewidth]%
            (0,0)(\fpeval{\radius-0.1},0){1}{EndNode}}}
        \visible<5->{\andelB[yellow!70]{\start}{\eleverSumNul}}
        \visible<6->{\andelB[red!70]{\eleverSumNul}{\eleverSumEn}}
        \visible<7->{\andelB[green!80]{\eleverSumEn}{\eleverSumTo}}
        \visible<8->{\andelB[orange!80]{\eleverSumTo}{\eleverSumTre}}
        \visible<9->{\andelB[blue!70!white]{\eleverSumTre}{\eleverSumFire}}
        \visible<10->{\andelB[black]{\eleverSumFire}{\eleverSumFem}}
      \end{pspicture}
    \end{center}
    \end{frame}

    \end{document} 

在此处输入图片描述

添加:在 的定义中使用值 5.3 作为 的第一个参数\uput(代替 2)\andelB,您将获得大圆圈外的标签。(在这种情况下,不要忘记删除\textcolor{white}黑色区域):

在此处输入图片描述

答案2

的强制参数\uput{<distance>}定义了放置内容的位置与相关点之间的距离。您在宏8pt中使用\andelB...将其增加到更大的值,例如25pt

在此处输入图片描述

\def\andelB[#1]#2#3#4{%
  \pswedge[fillstyle = solid, fillcolor = #1]%
     {\radius}{\fpeval{round(#2/\eleverTotal*360,9)}}{\fpeval{round(#3/\eleverTotal*360,9)}}
  \ifstrequal{#1}{black}%
    {\psarc[linecolor = white]%
       (0,0){0.5}{\fpeval{round(#2/\eleverTotal*360,9)}}{\fpeval{round(#3/\eleverTotal*360,9)}}
     \uput{25pt}[\fpeval{round((#2+#3)/\eleverTotal*180,9)}]%
       (0,0){\textcolor{white}{\footnotesize\SI{\fpeval{round((#3-#2)/\eleverTotal*360)}}{\degree}}}}
    {\psarc%
       (0,0){0.5}{\fpeval{round(#2/\eleverTotal*360,9)}}{\fpeval{round(#3/\eleverTotal*360,9)}}
     \uput{25pt}[\fpeval{round((#2+#3)/\eleverTotal*180,9)}]%
       (0,0){\footnotesize\SI{\fpeval{round((#3-#2)/\eleverTotal*360)}}{\degree}}}%
}

答案3

\psset{
  unit = 0.4,opacity=0.5,
  linejoin = 1
}

在此处输入图片描述

但是,你可以愚弄\psChart宏来完成所有的计算:

\documentclass{beamer}
\usepackage{pstricks-add}
\newcounter{temp}
\def\Chart{\psChart{55,28,69,97,69,42}{}{4}}
\begin{document}

\begin{frame}{Opgave~$7$}
\begin{center}
\begin{pspicture}(-3,-3)(3,3)
\visible<1->{%
  \psset{userColor={yellow!70,white,white,white,white,white}}\Chart
  \rput(psChartI1){55}}
\visible<2->{%
  \psset{userColor={yellow!70,red!70,white,white,white,white}}\Chart
  \rput(psChartI1){55}\rput(psChartI2){28}}
\visible<3->{%
  \psset{userColor={yellow!70,red!70,green!80,white,white,white}}\Chart
  \rput(psChartI1){55}\rput(psChartI2){28}\rput(psChartI3){69}}
\visible<4->{%
  \setcounter{temp}{0}%
  \psset{userColor={yellow!70,red!70,green!80,orange!80,white,white}}\Chart
  \psforeach{\iA}{55,28,69,97}{\stepcounter{temp}\rput(psChartI\thetemp){\iA}}}
\visible<5->{%
  \setcounter{temp}{0}%
  \psset{userColor={yellow!70,red!70,green!80,orange!80,blue!70!white,white}}\Chart
  \psforeach{\iA}{55,28,69,97,69}{\stepcounter{temp}\rput(psChartI\thetemp){\iA}}}
\visible<6>{%
  \setcounter{temp}{0}%
  \psset{userColor={yellow!70,red!70,green!80,orange!80,blue!70!white,black}}\Chart
  \psforeach{\iA}{55,28,69,97,69}{\stepcounter{temp}\rput(psChartI\thetemp){\iA}}
  \rput(psChartI6){\color{white}42}}
\pscircle{4}
\degrees[26]\multido{\iA=0+1}{26}{\psline(4;\iA)(4.1;\iA)}
\end{pspicture}
\end{center}
\end{frame}

\end{document}

在此处输入图片描述

答案4

只是为了好玩:一个 TiZ 替代方案。您只需指定数字和颜色列表,

\def\LstNums{4,2,5,7,5,3}
\def\LstColors{"yellow!70","red!70","green!80","orange!80","blue!70!white","black"}

代码将完成剩下的工作。根据 RGB 颜色模型,选择与填充颜色互补的标签颜色。(其他颜色模型看起来可能更好/不同。)这样标签和内弧就可见了。动画从幻灯片 4(\def\istart{4})开始,如您的代码所示。

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles,backgrounds}
% from https://tex.stackexchange.com/a/283618
\newcommand{\convertdirectly}[3][hsb]{\begingroup%
  \extractcolorspecs{#2}{\modelcmd}{\colorcmd}%
  \convertcolorspec{\modelcmd}{\colorcmd}{#1}{\tmp}%
  \aftergroupdef#3\tmp}
\begin{document}

\begin{frame}[t]
\frametitle{Opgave~$7$}
\begin{center}
\begin{tikzpicture}[declare function={R=3;}]
 \def\istart{4}
 \def\LstNums{4,2,5,7,5,3}
 \def\LstColors{"yellow!70","red!70","green!80","orange!80","blue!70!white","black"}
 \def\mysum{0}
 \foreach \X [remember=\mysum as \mysum]in \LstNums
 {\pgfmathsetmacro{\mysum}{\mysum+\X}
 \xdef\pgfmathresult{\mysum}}
 \edef\mytotal{\pgfmathresult}
 \pgfmathtruncatemacro{\mydim}{dim(\LstNums)-1}
 \draw[thick,visible on=<\istart->] circle[radius=R*1cm]
 foreach \X in {0,10,...,350} {(\X:R) -- (\X:R+0.05)};
 \def\mysum{0}
 \foreach \X [remember=\mysum as \mysum] in {0,...,\mydim}
 {\pgfmathsetmacro{\mypercentage}{{\LstNums}[\X]/\mytotal}
  \pgfmathsetmacro{\mycolor}{{\LstColors}[\X]}
   \begin{scope}[on background layer]
   \draw[visible on=<\the\numexpr\istart+1+\X\relax->,fill=\mycolor]
    (0,0) -- (\mysum:R) arc(\mysum:\mysum+\mypercentage*360:R) --cycle;
  \end{scope}   
  \convertdirectly[RGB]{\mycolor}{\currRGB}
  \pgfmathtruncatemacro{\currR}{255-{\currRGB}[0]}
  \pgfmathtruncatemacro{\currG}{255-{\currRGB}[1]}
  \pgfmathtruncatemacro{\currB}{255-{\currRGB}[2]}
  \definecolor{tmp}{RGB}{\currR,\currG,\currB}
  \draw[visible on=<\the\numexpr\istart+1+\X\relax->,color=tmp,thick] 
   (\mysum:0.2*R) arc(\mysum:\mysum+\mypercentage*360:0.2*R)
   (\mysum+\mypercentage*180:0.6*R) node
   {$\pgfmathparse{int(360*\mypercentage+0.5)}\pgfmathresult^\circ$};
  \pgfmathsetmacro{\mysum}{\mysum+{\LstNums}[\X]*360/\mytotal} 
 }
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}

在此处输入图片描述

如果将标签移近中心,它们将不会被楔子覆盖,因为楔子是在图层上绘制的background

\PassOptionsToPackage{cmyk}{xcolor}
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles,backgrounds}
% from https://tex.stackexchange.com/a/283618
\newcommand{\convertdirectly}[3][hsb]{\begingroup%
  \extractcolorspecs{#2}{\modelcmd}{\colorcmd}%
  \convertcolorspec{\modelcmd}{\colorcmd}{#1}{\tmp}%
  \aftergroupdef#3\tmp}
\begin{document}

\begin{frame}[t]
\frametitle{Opgave~$7$}
\begin{center}
\begin{tikzpicture}[declare function={R=3;}]
 \def\istart{4}
 \def\LstNums{4,2,5,7,5,3}
 \def\LstColors{"yellow!70","red!70","green!80","orange!80","blue!70!white","black"}
 \def\mysum{0}
 \foreach \X [remember=\mysum as \mysum]in \LstNums
 {\pgfmathsetmacro{\mysum}{\mysum+\X}
 \xdef\pgfmathresult{\mysum}}
 \edef\mytotal{\pgfmathresult}
 \pgfmathtruncatemacro{\mydim}{dim(\LstNums)-1}
 \draw[thick,visible on=<\istart->] circle[radius=R*1cm]
 foreach \X in {0,10,...,350} {(\X:R) -- (\X:R+0.05)};
 \def\mysum{0}
 \foreach \X [remember=\mysum as \mysum] in {0,...,\mydim}
 {\pgfmathsetmacro{\mypercentage}{{\LstNums}[\X]/\mytotal}
  \pgfmathsetmacro{\mycolor}{{\LstColors}[\X]}
   \begin{scope}[on background layer]
   \draw[visible on=<\the\numexpr\istart+1+\X\relax->,fill=\mycolor]
    (0,0) -- (\mysum:R) arc(\mysum:\mysum+\mypercentage*360:R) --cycle;
  \end{scope}   
  \convertdirectly[cmy]{\mycolor}{\currhsb}
  \pgfmathsetmacro{\currc}{1-{\currhsb}[0]}
  \pgfmathsetmacro{\currm}{1-{\currhsb}[1]}
  \pgfmathsetmacro{\curry}{1-{\currhsb}[2]}
  \definecolor{tmp}{cmy}{\currc,\currm,\curry}
  \draw[visible on=<\the\numexpr\istart+1+\X\relax->,color=tmp,thick] 
   (\mysum:0.2*R) arc(\mysum:\mysum+\mypercentage*360:0.2*R)
   node[midway,circle,inner sep=1pt,anchor=180+\mysum+\mypercentage*180]
   {$\pgfmathparse{int(360*\mypercentage+0.5)}\pgfmathresult^\circ$};
  \pgfmathsetmacro{\mysum}{\mysum+{\LstNums}[\X]*360/\mytotal} 
 }
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}

在此处输入图片描述

这里我使用了cmy颜色模型。当然,很有可能有比 更好的映射x\mapsto 1-xx\in\{c,m,y\}但在我看来,结果的可读性很好。

相关内容