在饼图中插入文本

在饼图中插入文本

我尝试在节点中插入文本,需要帮助。如何修复每个文本的位置?谢谢

\documentclass[border=10pt]{standalone}%{article}
%\usepackage[papers=30cm,paperwidth=35cm,margin=1in,heightrounded]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\thispagestyle{empty}
\fbox{\begin{tikzpicture}[scale=0.2] % pour rester dans la page
% center
\path  (0,0) coordinate(A);
% circles
\foreach \rr in {12,...,25}{
  \draw  (A) circle (\rr);
}
\def\pp{4} % nb of slices
% Assume the percentage is 20,10,20,10 respectively for the 4 slice
\foreach \aa in {0,20,30,50,60}{
\draw ($(A)+({\aa*36/10}:12)$) --  ($(A)+({\aa*36/10}:25)$);
}
Insert text  
\draw ($(A)+(0/\pp*360+60.5:18)$) node[rotate=(100/\pp*60)]{\textcolor{blue}{long text1}};
\draw ($(A)+(0/\pp*360+50.5:21.5)$) node[rotate=(120/\pp*70)]{long text };
\draw ($(A)+(0/\pp*360+40.5:21.5)$) node[rotate=(120/\pp*70)]{\textcolor{red}{long text}};
\draw ($(A)+(0/\pp*360+30.5:21.5)$) node[rotate=(120/\pp*70)]{\textcolor{yellow}{long text}};
\draw ($(A)+(0/\pp*360+20.5:21.5)$) node[rotate=(120/\pp*70)]{\textcolor{blue}{long text}};

\end{tikzpicture}}
\end{document}

结果

答案1

我编写了一个宏 ( \curvedtext),它可以帮助您完成这项工作。该宏按照适当的弧线绘制“曲线”文本。它接收四个参数:

  1. 文本中心所在的角度
  2. 圆心到文字中心的距离
  3. 文本的颜色
  4. 文本

请参阅以下示例:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,decorations.text}
\begin{document}

\def\curvedtext#1#2#3#4{%
\path[decorate, decoration={text along path, text align=center, text={|\color{#3}\small|#4}}]
($(A)+(#1+20:#2)$) arc (#1+20:#1-20:#2);
}

\fbox{\begin{tikzpicture}[scale=0.2] % pour rester dans la page
% center
\path  (0,0) coordinate(A);
% circles
\foreach \rr in {12,...,25}{
  \draw  (A) circle (\rr);
}
\def\pp{4} % nb of slices
% Assume the percentage is 20,10,20,10 respectively for the 4 slice
\foreach \aa in {0,20,30,50,60}{
\draw ($(A)+({\aa*36/10}:12)$) --  ($(A)+({\aa*36/10}:25)$);
}

\curvedtext{50.5}{21}{blue}{long text};
\curvedtext{40.5}{20}{red}{longer text};
\curvedtext{30.5}{19}{green!60!black}{even longer text};
\end{tikzpicture}}  
\end{document}

结果:

结果

相关内容