# Why the shift in tikz doesn't work?

I like the ring diagram, so I want to use a kind of ring diagram in my document. Thank Jack for the answer Ring Diagram(https://tex.stackexchange.com/users/2552/jake). However when I use the code in my document, the diagram isn't at a fine position. So i want to xshift it. However the command xshift doesn't work! What hapened?

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}

% Adjusts the size of the wheel:

% 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
% 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...

% 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?
\end{tikzpicture}
}
\wheelchart{26/cyan/Corporate,  28/orange/Plastique, 33.5/yellow/Chimique, 12.5/blue!50!red/Rhodia}

\end{document}


xshift=0cm

xshift=-2cm

These 2 pictures above are the real outputs after I change the xshift paragram(where? \begin{scope}[xshift=-1cm,rotate=-90]). So why? Thank you for reading and answers. I had installed the texlive 2017.

I want the colored circle to shift along x-axis. The length can be decided by me. Because my document has two columms like this.

The colored circle now is at the left column, however I want to move it to the right column like this;

In this way, there are some mistakes which you can see in the picture above.I tried to xshift,but it failed. And last night I took advice and used the \clip to fix my problem. But Why does xshift not work as I want?(move towards left)

• The shift for scopes has only an effect it you have another object inside your tikzpicture outside the scope. Otherwise - as in your case - this will not have any visible effect. Jul 10 '17 at 14:00
• You should probably try the \clip-command to reduce/add whitespaces and you might want to think of using a float. Compare tex.stackexchange.com/questions/49039/…. Jul 10 '17 at 14:02
• @epR8GaYuh thanks a lot for your comment. In fact, my document has two columns. The diagram is at a too left position, so that it only has the left half in the page and the right half disappears. So I want to add some xshift(eg. xshift=-1cm), however it doesn't move at all. Jul 10 '17 at 14:32
• @CampanIgnis I tried your solution, but it didn't work. I did like this: \end{scope} \clip (-3cm,-2.5cm) rectangle (5cm,2.5cm);... and  \end{scope} \clip (-0cm,-2.5cm) rectangle (5cm,2.5cm);... I noticed that the output pictues were the same. Jul 10 '17 at 14:33
• @CampanIgnis Thanks a lot for advice, the \clip-command does work for my problem. Jul 10 '17 at 15:02

Your problem is that everything outside the tikzpicture adds space the the left or right of the tikzpicture. I added some code to draw the bounding box, then removed the extra spaces until the bounding box matched the edges of the standalone.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}

% Adjusts the size of the wheel:

% 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
% 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...

% 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?
\end{tikzpicture}%
}

\begin{document}
\wheelchart{26/cyan/Corporate,  28/orange/Plastique, 33.5/yellow/Chimique, 12.5/blue!50!red/Rhodia}%
\end{document}


If you want to center the origin inside the bounding box, you can use the following (either before, after or instead of drawing the bounding box). It requires the calc tikzlibrary.

\path ($(current bounding box.south west)!2!(0,0)$);
\path ($(current bounding box.north east)!2!(0,0)$);

• Thanks for your answer. It can fix my problem. And I found it was the extra spaces that disturbed me. I compared your code and my previous code. I found nothing but the line \draw[green] (current bounding box.south west) rectangle (current bounding box.north east); So where is your magical code ? Jul 11 '17 at 7:31
• Every line that ends with { or } adds a space, whereate {% and }% do not. Also, I moved \begin{document} back as far as possible. Jul 11 '17 at 15:48