如何在 \uput 中使用 \def 命令

如何在 \uput 中使用 \def 命令
\documentclass[12pt,border=5pt]{standalone}
\usepackage{newcent,pstricks-add,multido} 
\usepackage{auto-pst-pdf}
\begin{document}
\begin{pspicture}

\def\stuff1{Môi trường Vật lý}
\def\stuff2{Sự lãng mạn}
\def\stuff3{Sự nghiệp}
\def\stuff4{Gia đình/Bạn bè}
\def\stuff5{Tài chính}
\def\stuff6{Phát triển bản thân}
\def\stuff7{Sức khỏe}
\def\stuff8{Niềm vui/Giải trí}

\psChart[userColor={cyan,green,red,blue,teal,brown,gray,pink}] 
 {20,20,20,20,20,20,20,20}{}{2}
\multido{\r=-1.75+0.5,\n=8+-1}{8}{
     \psset{fillstyle=solid,dotstyle=square,dotscale=2}
     \def\a{3.5}
     \psdot[fillcolor=chartFillColor\n](\a,\r)
     \uput[0](\a,\r){\stuff\n}  }
 \end{pspicture}
 \end{document}

它产生:

enter image description here

其产生方式如下:

enter image description here

一个相关问题:

为什么将 {20,20,20,20,20,20,20,20} 编译的结果为 {10,10,10,10,10,10,10,10} 或 {45,45,45,45,45,45,45,45}?

答案1

作为 的强制参数的一部分指定的序列\psChart表示每个部分占整个饼图的比例。因此,将使用与和{20,20,20,20,20,20,20,20}相同的比例(或各占 12.5%)。如果您指定不同的数字,您会注意到饼图切片大小的差异。{10,10,10,10,10,10,10,10}{45,45,45,45,45,45,45,45}

enter image description here

\documentclass{article}

\usepackage{pstricks-add,multido}

\begin{document}

\begin{pspicture}

  \expandafter\def\csname stuff1\endcsname{First}
  \expandafter\def\csname stuff2\endcsname{Second}
  \expandafter\def\csname stuff3\endcsname{Third}
  \expandafter\def\csname stuff4\endcsname{Fourth}
  \expandafter\def\csname stuff5\endcsname{Fifth}
  \expandafter\def\csname stuff6\endcsname{Sixth}
  \expandafter\def\csname stuff7\endcsname{Seventh}
  \expandafter\def\csname stuff8\endcsname{Eighth}

  \psChart[
    userColor={cyan,green,red,blue,teal,brown,gray,pink}
  ]
    {1,1,1,1,1,1,1,1}{}{2}

  \def\a{3.5}
  \multido{\r=-1.75+0.5,\n=8+-1}{8}{
    \psset{fillstyle=solid,dotstyle=square,dotscale=2}
    \psdot[fillcolor=chartFillColor\n](\a,\r)
    \uput[0](\a,\r){\csname stuff\n\endcsname}
  }

  \psframe(3,-2)(5.5,2)

\end{pspicture}

\end{document}

答案2

\documentclass[12pt]{article}
\usepackage{newcent,pstricks-add,multido} 
\usepackage{auto-pst-pdf}

\def\stuff#1{%
    \ifcase #1
    \or {Môi trường Vật lý}
    \or {Sự lãng mạn}
    \or {Sự nghiệp}
    \or {Gia đình/Bạn bè}
    \or {Tài chính}
    \or {Phát triển bản thân}
    \or {Sức khỏe}
    \or {Niềm vui/Giải trí}
    \fi}
\begin{document}

\begin{pspicture}(-5,-5)(10,5)  
\psChart[userColor={cyan,green,red,blue,teal,brown,gray,pink}]{20,20,20,20,20,20,20,20}{}{2}
\psset{fillstyle=solid,dotstyle=square,dotscale=2}%
\def\a{3.5}%
\multido{\r=-1.75+0.5,\n=8+-1}{8}{%
  \psdot[fillcolor=chartFillColor\n](\a,\r) \uput[0](\a,\r){\stuff{\n}}%
}
\end{pspicture}

\end{document}

enter image description here

相关内容