如何在圆圈上方制作一个(漂亮的)标题?

如何在圆圈上方制作一个(漂亮的)标题?

问题就在标题里。提前谢谢您。

以下是代码

\documentclass[tikz]{standalone}
\begin{document}
\def\angle{0}
\def\radius{3}
\def\cyclelist{{"orange","blue","red","green"}}
\newcount\cyclecount \cyclecount=-1
\newcount\ind \ind=-1
\begin{tikzpicture}
  \foreach \percent/\name in {
      32.9/Union,
      20.5/SPD,
      12.6/AfD,
      10.7/FDP,
      9.2/Linke,
      8.9/Gr{\"u}ne,
      5.2/parteilose
    } {
      \ifx\percent\empty\else                 
        \global\advance\cyclecount by 1       
        \global\advance\ind by 1              
        \ifnum3<\cyclecount                  
          \global\cyclecount=0                
          \global\ind=0                       
        \fi
        \pgfmathparse{\cyclelist[\the\ind]}   
        \edef\color{\pgfmathresult}          

        \draw[fill={\color!50},draw={\color}] (0,0) -- (\angle:\radius) arc (\angle:\angle+\percent*3.6:\radius) -- cycle;
        \node at (\angle+0.5*\percent*3.6:0.7*\radius) {\percent\%};
        \node[pin=\angle+0.5*\percent*3.6:\name] at (\angle+0.5*\percent*3.6:\radius) {};
        \pgfmathparse{\angle+\percent*3.6}    
        \xdef\angle{\pgfmathresult}           
      \fi
    };
    %\tkzText[above](5){Ergebnisse Bundestagswahl}
\end{tikzpicture}
\end{document}

答案1

这够花哨吗?

在此处输入图片描述

\documentclass[tikz,border=3.14pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{fadings}
% from https://tex.stackexchange.com/a/59544/121799
\pgfkeys{%
/piechartthreed/.cd,
scale/.code                =  {\def\piechartthreedscale{#1}},
mix color/.code            =  {\def\piechartthreedmixcolor{#1}},
background color/.code     =  {\def\piechartthreedbackcolor{#1}},
name/.code                 =  {\def\piechartthreedname{#1}}}

 \newcommand\piechartthreed[2][]{% 
   \pgfkeys{/piechartthreed/.cd,
     scale            = 1,
     mix color        = gray,
     background color = white,
     name             = pc} 
  \pgfqkeys{/piechartthreed}{#1}
  \begin{scope}[scale=\piechartthreedscale] 
  \begin{scope}[xscale=5,yscale=3] 
     \path[preaction={fill=black,opacity=.8,
         path fading=circle with fuzzy edge 20 percent,
         transform canvas={yshift=-15mm*\piechartthreedscale}}] (0,0) circle (1cm);
    \fill[gray](0,0) circle (0.5cm);  
     \path[preaction={fill=\piechartthreedbackcolor,opacity=.8,
          path fading=circle with fuzzy edge 20 percent,
          transform canvas={yshift=-10mm*\piechartthreedscale}}] (0,0) circle (0.5cm);
     \pgfmathsetmacro\totan{0} 
     \global\let\totan\totan 
     \pgfmathsetmacro\bottoman{180} \global\let\bottoman\bottoman 
     \pgfmathsetmacro\toptoman{0}   \global\let\toptoman\toptoman 
     \begin{scope}[draw=black,thin]
     \foreach \an/\col [count=\xi] in {#2}{%
     \def\space{ } 
        \coordinate (\piechartthreedname\space\xi) at (\totan+\an/2:0.75cm); 
        \ifdim 180pt>\totan pt 
         \ifdim 0pt=\toptoman pt
            \shadedraw[left color=\col!20!\piechartthreedmixcolor,
                       right color=\col!5!\piechartthreedmixcolor,
                       draw=black,very thin] (0:.5cm) -- ++(0,-3mm) arc (0:\totan+\an:.5cm) 
                                                       -- ++(0,3mm)  arc (\totan+\an:0:.5cm);
            \pgfmathsetmacro\toptoman{180} 
            \global\let\toptoman\toptoman         
            \else
            \shadedraw[left color=\col!20!\piechartthreedmixcolor,
                       right color=\col!5!\piechartthreedmixcolor,
                       draw=black,very thin](\totan:.5cm)-- ++(0,-3mm) arc(\totan:\totan+\an:.5cm)
                                                        -- ++(0,3mm)  arc(\totan+\an:\totan:.5cm); 
          \fi
        \fi   
        \fill[\col!20!gray,draw=black] (\totan:0.5cm)--(\totan:1cm)  arc(\totan:\totan+\an:1cm)
                                     --(\totan+\an:0.5cm) arc(\totan+\an:\totan :0.5cm);     
       \pgfmathsetmacro\finan{\totan+\an}
       \ifdim 180pt<\finan pt 
         \ifdim 180pt=\bottoman pt
            \shadedraw[left color=\col!20!\piechartthreedmixcolor,
                       right color=\col!5!\piechartthreedmixcolor,
                       draw=black,very thin] (180:1cm) -- ++(0,-3mm) arc (180:\totan+\an:1cm) 
                                                       -- ++(0,3mm)  arc (\totan+\an:180:1cm);
            \pgfmathsetmacro\bottoman{0}
            \global\let\bottoman\bottoman
            \else
            \shadedraw[left color=\col!20!\piechartthreedmixcolor,
                       right color=\col!5!\piechartthreedmixcolor,
                       draw=black,very thin](\totan:1cm)-- ++(0,-3mm) arc(\totan:\totan+\an:1cm)
                                                        -- ++(0,3mm)  arc(\totan+\an:\totan:1cm); 
          \fi
        \fi
        \pgfmathsetmacro\totan{\totan+\an}  \global\let\totan\totan 
       } 
    \end{scope}
    \draw[thin,black](0,0) circle (0.5cm);
   \end{scope}  
\end{scope}
}
%
\tikzset{CastShadow/.style={anchor=south,inner sep=0,font=\sffamily\Huge}}
\newcommand{\CastShadow}[2][]{
  \node[CastShadow,#1]{#2};
  \node[scope fading=south,opacity=0.4,yscale=-1,CastShadow,#1]{#2};
}

\begin{document} 
 \begin{tikzpicture}
   \piechartthreed[scale=0.8,
                   background color=orange!50,
                   mix color= darkgray]
                   {32.9*3.6/black,20.5*3.6/red,12.6*3.6/blue,10.7*3.6/yellow,
                   9.2*3.6/pink,8.9*3.6/green!50!black,5.2*3.6/orange}
   \foreach \i in {1,...,7} { \fill (pc \i) circle (.5mm);}
   \draw[darkgray] (pc 1)  -- ++(5,0) coordinate (s1) node[anchor=south east]
   {Union}
                                                      node[anchor=north east] {32.9\%};
   \draw[darkgray] (pc 2)  -- ++(-2,1) -- ++(-2,0) coordinate (s2)  node[anchor=south west] {SPD}
                                                      node[anchor=north west] {20.5\%}; 
   \draw[darkgray] (pc 3)  -- ++(-4,0) coordinate (s3) node[anchor=south west] {AfD}
                                                      node[anchor=north west] {12.6\%};
   \draw[darkgray] (pc 4)  -- ++(-1,-1) coordinate (s4) --(s4 -| s3)
   node[anchor=south west] {FDP}
                                                      node[anchor=north west]
                                                      {10.7\%};
   \draw[darkgray] (pc 5) -- ++(2,-1) coordinate (s5) -- (s5 -| s1) node[anchor=south east] {Linke}
                                                      node[anchor=north east]
                                                      {9.8\%}; 
   \draw[darkgray] (pc 6) -- ++(2,-0.5) coordinate (s6) -- (s6 -| s1) node[anchor=south east] {Gr{\"u}ne}
                                                      node[anchor=north east]
                                                      {8.9\%}; 
   \draw[darkgray] (pc 7) -- (pc 7 -| s1) node[anchor=south east] {parteilose}
                                                      node[anchor=north east]
                                                      {5.2\%}; 
    \CastShadow[at={(0,5)}]{Ergebnisse Bundestagswahl}
 \end{tikzpicture}

\end{document}

相关内容