私はリング図が好きなので、文書でリング図のようなものを使いたいと思っています。回答してくれたジャックに感謝します。リング図(https://tex.stackexchange.com/users/2552/jake)。しかし、ドキュメントでコードを使用すると、図が適切な位置にありません。そのため、xshift を実行したいのですが、コマンド xshift が機能しません。何が起こったのでしょうか?
\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}
上記の 2 つの画像は、パラグラムを変更した後の実際の出力ですxshift
(どこですか? \begin{scope}[xshift=-1cm,rotate=-90]
)。では、なぜでしょうか?読んで回答していただきありがとうございます。texlive 2017 をインストールしました。
色付きの円を x 軸に沿って移動させたいです。長さは自分で決められます。私のドキュメントにはこのように 2 つの列があるためです。
色付きの円は現在左の列にありますが、次のように右の列に移動したいと思います。
このように、上の写真でわかるように、いくつかの間違いがあります。xshift を試しましたが、失敗しました。昨夜、アドバイスを受けて、 を使って\clip
問題を解決しました。しかし、なぜxshift
思ったように動作しないのでしょうか?(左に向かって移動)
答え1
問題は、tikzpicture の外側にあるものすべてが、tikzpicture の左または右にスペースを追加することです。境界ボックスを描画するコードを追加し、境界ボックスがスタンドアロンの端と一致するまで余分なスペースを削除しました。
\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}
境界ボックス内で原点を中央に配置する場合は、以下を使用できます (境界ボックスを描画する前、描画した後、または描画の代わりに)。tikz ライブラリが必要ですcalc
。
\path ($(current bounding box.south west)!2!(0,0)$);
\path ($(current bounding box.north east)!2!(0,0)$);