据我理解,以下代码中的阴影是在范围转换之后应用的。
\documentclass[varwidth,margin=0.5cm]{standalone}
\usepackage{tikz}
\begin{document}
\pgfdeclareverticalshading{myshade}{2cm}{
color(0cm)=(red);
color(.3cm)=(orange);
color(.6cm)=(yellow);
color(.9cm)=(green);
color(1.2cm)=(blue);
color(1.5cm)=(purple);
color(1.8cm)=(brown)
}
\begin{tikzpicture}
\begin{scope}[rotate=26.73]
\draw [shading=myshade] (0, 0) circle (1);
\end{scope}
\end{tikzpicture}
\begin{tikzpicture}
\begin{scope}
\draw [shading=myshade] (0, 0) circle (1);
\end{scope}
\end{tikzpicture}
\end{document}
假设圆是旋转对称的,那么两个 tikzpicture 的结果应该相同。但阴影却不同。为什么会这样?
答案1
阴影是根据边界框完成的,例如这里。圆是由贝塞尔曲线构成的,这意味着它的边界框在旋转时会发生变化。如您所见,出于同样的原因,圆圈也没有垂直对齐。一旦修复边界框,效果就消失了。
\documentclass[varwidth,margin=0.5cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{bbox}
\begin{document}
\pgfdeclareverticalshading{myshade}{2cm}{
color(0cm)=(red);
color(.3cm)=(orange);
color(.6cm)=(yellow);
color(.9cm)=(green);
color(1.2cm)=(blue);
color(1.5cm)=(purple);
color(1.8cm)=(brown)
}
\begin{tikzpicture}[bezier bounding box]
\begin{scope}[rotate=26.73]
\draw [shading=myshade] (0, 0) circle (1);
\end{scope}
\end{tikzpicture}
\begin{tikzpicture}[bezier bounding box]
\begin{scope}
\draw [shading=myshade] (0, 0) circle (1);
\end{scope}
\end{tikzpicture}
\end{document}
如果要旋转阴影,请更改shading angle
。(您也可以使用,transform canvas
但有时这有点难以驯服。)
\documentclass[varwidth,margin=0.5cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{bbox}
\begin{document}
\pgfdeclareverticalshading{myshade}{2cm}{
color(0cm)=(red);
color(.3cm)=(orange);
color(.6cm)=(yellow);
color(.9cm)=(green);
color(1.2cm)=(blue);
color(1.5cm)=(purple);
color(1.8cm)=(brown)
}
\begin{tikzpicture}[bezier bounding box]
\path (0, 0) circle[radius=1];
\begin{scope}[transform canvas={rotate=26.73}]
\draw [shading=myshade] (0, 0) circle[radius=1];
\end{scope}
\end{tikzpicture}
\begin{tikzpicture}[bezier bounding box]
\begin{scope}
\draw [shading=myshade,shading angle=26.73] (0, 0) circle[radius=1];
\end{scope}
\end{tikzpicture}
\begin{tikzpicture}[bezier bounding box]
\begin{scope}
\draw [shading=myshade] (0, 0) circle[radius=1];
\end{scope}
\end{tikzpicture}
\end{document}