
Gosto do diagrama de anéis, então quero usar uma espécie de diagrama de anéis em meu documento. Obrigado Jack pela resposta Diagrama de Anel (https://tex.stackexchange.com/users/2552/jake). No entanto, quando uso o código no meu documento, o diagrama não está em uma posição adequada. Então eu quero xshift isso. Porém o comando xshift não funciona! O que aconteceu?
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
% Adjusts the size of the wheel:
\def\innerradius{1.cm}
\def\outerradius{2cm}
% The main macro
\newcommand{\wheelchart}[1]{
% Calculate total
\pgfmathsetmacro{\totalnum}{0}
\foreach \value/\colour/\name in {#1} {
\pgfmathparse{\value+\totalnum}
\global\let\totalnum=\pgfmathresult
}
\begin{tikzpicture}
% Calculate the thickness and the middle line of the wheel
\pgfmathsetmacro{\wheelwidth}{\outerradius-\innerradius}
\pgfmathsetmacro{\midradius}{(\outerradius+\innerradius)/2}
\draw[red] (0,0) circle [radius=2.5cm];
% Rotate so we start from the top
\begin{scope}[xshift=-1cm,rotate=90]%%here I want to xshift
% Loop through each value set. \cumnum keeps track of where we are in the wheel
\pgfmathsetmacro{\cumnum}{0}
\foreach \value/\colour/\name in {#1} {
\pgfmathsetmacro{\newcumnum}{\cumnum + \value/\totalnum*360}
% Calculate the percent value
\pgfmathsetmacro{\percentage}{\value/\totalnum*100}
% Calculate the mid angle of the colour segments to place the labels
\pgfmathsetmacro{\midangle}{-(\cumnum+\newcumnum)/2}
% This is necessary for the labels to align nicely
\pgfmathparse{
(-\midangle<180?"west":"east")
} \edef\textanchor{\pgfmathresult}
\pgfmathsetmacro\labelshiftdir{1-2*(-\midangle>180)}
% Draw the color segments. Somehow, the \midrow units got lost, so we add 'pt' at the end. Not nice...
\fill[\colour] (-\cumnum:\outerradius) arc (-\cumnum:-(\newcumnum):\outerradius) --
(-\newcumnum:\innerradius) arc (-\newcumnum:-(\cumnum):\innerradius) -- cycle;
% Draw the data labels
\draw [*-,thin] node [append after command={(\midangle:\midradius pt) -- (\midangle:\outerradius + 1ex) -- (\tikzlastnode)}] at (\midangle:\outerradius + 1ex) [xshift=\labelshiftdir*0.5cm,inner sep=0pt, outer sep=0pt, ,anchor=\textanchor]{\name: \pgfmathprintnumber{\percentage}\%};
% Set the old cumulated angle to the new value
\global\let\cumnum=\newcumnum
}
\end{scope}
\clip (-0cm,-2.5cm) rectangle (5cm,2.5cm);%there should be some problems but the tikz ignores it, why?
%\draw[gray] (0,0) circle (\outerradius) circle (\innerradius);
\end{tikzpicture}
}
\wheelchart{26/cyan/Corporate, 28/orange/Plastique, 33.5/yellow/Chimique, 12.5/blue!50!red/Rhodia}
\end{document}
Essas 2 imagens acima são as saídas reais depois que eu altero o xshift
parâmetro (onde? \begin{scope}[xshift=-1cm,rotate=-90]
). Então por que? Obrigado pela leitura e respostas. Eu tinha instalado o texlive 2017.
Quero que o círculo colorido se desloque ao longo do eixo x. O comprimento pode ser decidido por mim. Porque meu documento tem duas colunas como esta.
O círculo colorido agora está na coluna da esquerda, porém quero movê-lo para a coluna da direita assim;
Desta forma, existem alguns erros que você pode ver na imagem acima. Tentei xshift, mas falhou. E ontem à noite segui um conselho e usei o \clip
para resolver meu problema. Mas por que xshift
não funciona como eu quero? (mover para a esquerda)
Responder1
Seu problema é que tudo fora do tikzpicture adiciona espaço à esquerda ou à direita do tikzpicture. Adicionei algum código para desenhar a caixa delimitadora e removi os espaços extras até que a caixa delimitadora correspondesse às bordas do autônomo.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
% Adjusts the size of the wheel:
\def\innerradius{1.cm}
\def\outerradius{2cm}
% The main macro
\newcommand{\wheelchart}[1]{%
% Calculate total
\pgfmathsetmacro{\totalnum}{0}%
\foreach \value/\colour/\name in {#1} {%
\pgfmathparse{\value+\totalnum}%
\global\let\totalnum=\pgfmathresult
}%
\begin{tikzpicture}
% Calculate the thickness and the middle line of the wheel
\pgfmathsetmacro{\wheelwidth}{\outerradius-\innerradius}
\pgfmathsetmacro{\midradius}{(\outerradius+\innerradius)/2}
\draw[red] (0,0) circle [radius=2.5cm];
% Rotate so we start from the top
\begin{scope}[rotate=90]%%here I want to xshift
% Loop through each value set. \cumnum keeps track of where we are in the wheel
\pgfmathsetmacro{\cumnum}{0}
\foreach \value/\colour/\name in {#1} {
\pgfmathsetmacro{\newcumnum}{\cumnum + \value/\totalnum*360}
% Calculate the percent value
\pgfmathsetmacro{\percentage}{\value/\totalnum*100}
% Calculate the mid angle of the colour segments to place the labels
\pgfmathsetmacro{\midangle}{-(\cumnum+\newcumnum)/2}
% This is necessary for the labels to align nicely
\pgfmathparse{
(-\midangle<180?"west":"east")
} \edef\textanchor{\pgfmathresult}
\pgfmathsetmacro\labelshiftdir{1-2*(-\midangle>180)}
% Draw the color segments. Somehow, the \midrow units got lost, so we add 'pt' at the end. Not nice...
\fill[\colour] (-\cumnum:\outerradius) arc (-\cumnum:-(\newcumnum):\outerradius) --
(-\newcumnum:\innerradius) arc (-\newcumnum:-(\cumnum):\innerradius) -- cycle;
% Draw the data labels
\draw [*-,thin] node [draw,append after command={(\midangle:\midradius pt) -- (\midangle:\outerradius + 1ex) -- (\tikzlastnode)}] at (\midangle:\outerradius + 1ex) [xshift=\labelshiftdir*0.5cm,inner sep=0pt, outer sep=0pt, anchor=\textanchor]{\name: \pgfmathprintnumber{\percentage}\%};
% Set the old cumulated angle to the new value
\global\let\cumnum=\newcumnum
}
\end{scope}
\draw[green] (current bounding box.south west) rectangle (current bounding box.north east);
%\clip (-0cm,-2.5cm) rectangle (5cm,2.5cm);%there should be some problems but the tikz ignores it, why?
%\draw[gray] (0,0) circle (\outerradius) circle (\innerradius);
\end{tikzpicture}%
}
\begin{document}
\wheelchart{26/cyan/Corporate, 28/orange/Plastique, 33.5/yellow/Chimique, 12.5/blue!50!red/Rhodia}%
\end{document}
Se quiser centralizar a origem dentro da caixa delimitadora, você pode usar o seguinte (antes, depois ou em vez de desenhar a caixa delimitadora). Requer a calc
biblioteca tikz.
\path ($(current bounding box.south west)!2!(0,0)$);
\path ($(current bounding box.north east)!2!(0,0)$);