Tikz-Diagramm (Torten-, Balkendiagramm) wahlweise im Hoch- oder Querformat
Ich habe nachfolgende Torten- und Balkendiagramme. Mir gefällt die Aufteilung/Position bei einem doppelseitigen Buch noch nicht. Nun würde ich gerne wahlweise die Diagramme im Hoch- und Querformat ausgeben, je nachdem, ob ich beide Diagramme oder nur eins ausgebe. Versuche mit **landscape** sind mir bislang misslungen.
\documentclass[fontsize=10pt,paper=a4,twoside]{scrbook}
\usepackage[table]{xcolor}
\usepackage{tikz}
\usepackage{blindtext}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\definecolor{framsokn}{RGB}{24,73,42}
\definecolor{sjalfstaedi}{RGB}{0,0,181}
\definecolor{vinstrigraen}{RGB}{72,142,65}
\definecolor{frjalslyndi}{RGB}{0,142,210}
\definecolor{samfylkingin}{RGB}{198,18,24}
\definecolor{borgarahreyfingin}{RGB}{242,120,31}
\definecolor{lydraedishrefingin}{RGB}{198,18,24}
\definecolor{klisti}{rgb}{255,247,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}
\blindtext
\newcommand\dataa{
29.80/Samfylkingin/samfylkingin,
23.70/Sjálfstæðisflokkur/sjalfstaedi,
21.68/Vinstrihreyfingin--grænt framboð/vinstrigraen,
14.80/Framsóknarflokkur/framsokn,
7.22/Borgarahreyfingin/borgarahreyfingin,
2.22/Frjálslyndi flokkurinn/frjalslyndi,
0.59/Lýðræðishreyfingin/lydraedishrefingin%
}
\newcommand\dataaa{
29.80/Samfylkingin/samfylkingin,
23.70/Sjálfstæðisflokkur/sjalfstaedi,
21.68/Vinstrihreyfingin--grænt framboð/vinstrigraen,
14.80/Framsóknarflokkur/framsokn,
7.22/Borgarahreyfingin/borgarahreyfingin,
2.81/Sonstige/klisti,
% 0.59/Lýðræðishreyfingin/lydraedishrefingin%
}
\begin{tikzpicture}[scale=1.00]
\begin{scope}
\global\ind=-1
\foreach \percent/\name/\color in \dataaa{
\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 \dataa{
\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+.14,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}