Überarbeitungsverlauf[Zurück]
Klicke auf Einblenden/Ausblenden von Überarbeitungen 2
Für Johannes

10 Jan '16, 16:42

Henri's gravatar image

Henri
15.7k133943

Ich speichere den Datensatz einfach im Makro `\data`, dann muss ich ihn nicht in jeder `\foreach` Schleife wiederholen. Das ganze würde prinzipiell auch in einer einzelnen Schleife gehen, ist meines Erachtens nach aber nicht praktikabel. \documentclass[tikz]{standalone} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \definecolor{deep brown}{RGB}{125,91,49} \definecolor{dark blue}{RGB}{0,0,181} \definecolor{dark green}{RGB}{72,142,65} \definecolor{crimson red}{RGB}{198,18,24} \definecolor{light red}{RGB}{255,51,0} \def\angle{0} \def\radius{3} \newcommand\square[1]{% \tikz\filldraw[color=#1] (0,0) rectangle (1.5ex,1.5ex);% } \newcount\ind \begin{document} \newcommand\data{ 14.8/Framsóknarflokkur/deep brown, 23.7/Sjálfstæðisflokkur/dark blue, 7.2/Borgarahreyfingin/blue, 0.6/Lýðræðishreyfingin/light red, 29.8/Samfylkingin/crimson red, 21.7/Vinstrihreyfingin--grænt framboð/dark green, 2.2/Sonstige/gray% } \begin{tikzpicture} \begin{scope} \global\ind=-1 \foreach \percent/\name/\color in \data { \ifx\percent\empty\else % If \percent is empty, do nothing \global\advance\ind by 1 % Advance list index % Draw angle and set labels \filldraw[color=\color] (0,0) -- (\angle:\radius) arc (\angle:\angle+\percent*3.6:\radius) -- cycle; \node[anchor=base west] at (\radius+2,1.5-.5*\ind) {\square{\color} \name}; \node[pin=\angle+0.5*\percent*3.6:\percent\%] at (\angle+0.5*\percent*3.6:\radius) {}; \pgfmathparse{\angle+\percent*3.6} % Advance angle \xdef\angle{\pgfmathresult} % and store in \angle \fi }; \end{scope} \pgfmathsetmacro\barmaxheight{5} \begin{scope}[shift={(-2,-4-\barmaxheight)}] \draw[<->] (0,\barmaxheight+0.5) |- (8,0); \draw (2pt,\barmaxheight) -- (-2pt,\barmaxheight) node[left] {100\%}; \draw (2pt,.5*\barmaxheight) -- (-2pt,.5*\barmaxheight) node[left] {50\%}; \global\ind=-1 \foreach \percent/\name/\color in \data { \ifx\percent\empty\else % If \percent is empty, do nothing \global\advance\ind by 1 % Advance list index % Draw angle and set labels \filldraw[color=\color] (\ind+.7,0) rectangle (\ind+1.2,\barmaxheight/100*\percent); \node[above] at (\ind+1,\barmaxheight/100*\percent) {\percent\%}; \node[rotate=45,anchor=north east] \node[rotate=45,anchor=base east,yshift=-1ex] at (\ind+1,0) {\name}; \fi }; \end{scope} \end{tikzpicture} \end{document} > ![alt text][1] [1]: http://texwelt.de/wissen/upfiles/test_28.pnghttp://texwelt.de/wissen/upfiles/test_29.png
Klicke auf Einblenden/Ausblenden von Überarbeitungen 1

10 Jan '16, 16:03

Henri's gravatar image

Henri
15.7k133943

Ich speichere den Datensatz einfach im Makro `\data`, dann muss ich ihn nicht in jeder `\foreach` Schleife wiederholen. Das ganze würde prinzipiell auch in einer einzelnen Schleife gehen, ist meines Erachtens nach aber nicht praktikabel. \documentclass[tikz]{standalone} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \definecolor{deep brown}{RGB}{125,91,49} \definecolor{dark blue}{RGB}{0,0,181} \definecolor{dark green}{RGB}{72,142,65} \definecolor{crimson red}{RGB}{198,18,24} \definecolor{light red}{RGB}{255,51,0} \def\angle{0} \def\radius{3} \newcommand\square[1]{% \tikz\filldraw[color=#1] (0,0) rectangle (1.5ex,1.5ex);% } \newcount\ind \begin{document} \newcommand\data{ 14.8/Framsóknarflokkur/deep brown, 23.7/Sjálfstæðisflokkur/dark blue, 7.2/Borgarahreyfingin/blue, 0.6/Lýðræðishreyfingin/light red, 29.8/Samfylkingin/crimson red, 21.7/Vinstrihreyfingin--grænt framboð/dark green, 2.2/Sonstige/gray% } \begin{tikzpicture} \begin{scope} \global\ind=-1 \foreach \percent/\name/\color in \data { \ifx\percent\empty\else % If \percent is empty, do nothing \global\advance\ind by 1 % Advance list index % Draw angle and set labels \filldraw[color=\color] (0,0) -- (\angle:\radius) arc (\angle:\angle+\percent*3.6:\radius) -- cycle; \node[anchor=base west] at (\radius+2,1.5-.5*\ind) {\square{\color} \name}; \node[pin=\angle+0.5*\percent*3.6:\percent\%] at (\angle+0.5*\percent*3.6:\radius) {}; \pgfmathparse{\angle+\percent*3.6} % Advance angle \xdef\angle{\pgfmathresult} % and store in \angle \fi }; \end{scope} \pgfmathsetmacro\barmaxheight{5} \begin{scope}[shift={(-2,-4-\barmaxheight)}] \draw[<->] (0,\barmaxheight+0.5) |- (8,0); \draw (2pt,\barmaxheight) -- (-2pt,\barmaxheight) node[left] {100\%}; \draw (2pt,.5*\barmaxheight) -- (-2pt,.5*\barmaxheight) node[left] {50\%}; \global\ind=-1 \foreach \percent/\name/\color in \data { \ifx\percent\empty\else % If \percent is empty, do nothing \global\advance\ind by 1 % Advance list index % Draw angle and set labels \filldraw[color=\color] (\ind+.7,0) rectangle (\ind+1.2,\barmaxheight/100*\percent); \node[above] at (\ind+1,\barmaxheight/100*\percent) {\percent\%}; \node[rotate=45,anchor=north east] at (\ind+1,0) {\name}; \fi }; \end{scope} \end{tikzpicture} \end{document} > ![alt text][1] [1]: http://texwelt.de/wissen/upfiles/test_28.png