倾斜 tikz 阴影

倾斜 tikz 阴影

我正在尝试绘制一条带阴影的带状图,覆盖整个页面。这条带状图应从西向东呈 15° 的小角度。但我似乎无法为阴影赋予“正确”的角度。该怎么做?它应该看起来像这样,只是倾斜了一点:

在此处输入图片描述

\documentclass{report}
\usepackage{tikz}
\pgfdeclareverticalshading{titlepage}{\paperwidth+3cm}
 {color(0cm)=(red); color(0.5cm)=(blue); color(3cm)=(yellow)}

\begin{document}
\begin{tikzpicture}[overlay,remember picture]

\shade[shading=titlepage,
       shading angle=15 %?????
       ]([yshift=4cm]current page.west)--++(15:1.2\paperwidth)--++(0,-2cm) --([yshift=2cm]current page.west)--cycle;

\shade[shading=axis,
       top color=yellow,
       bottom color=blue,
       %middle color=red,
       shading angle=30 %????
       ](current page.west)--++(15:1.2\paperwidth)--++(0,-2cm) --([yshift=-2cm]current page.west)--cycle;
\end{tikzpicture}
\mbox{}
\end{document}

在此处输入图片描述

答案1

Shade 总是使用边界矩形,因此 egreg 建议的“旋转和剪切”是一种可行的方法。transform canvas也可以使用,但有时会产生奇怪的副作用。

\documentclass{report}
\usepackage{tikz}
\pgfdeclareverticalshading{titlepage}{3cm}
 {color(0cm)=(red); color(0.5cm)=(blue); color(3cm)=(yellow)}
\newsavebox\UlrikeShading
\newsavebox\UlrikeShadingB
\begin{document}
\savebox\UlrikeShading{%
\tikz{\shade[shading=titlepage] (0,0) rectangle (2\paperwidth+3cm,2cm);}}
\savebox\UlrikeShadingB{%
\tikz{\shade[shading=axis,
       top color=yellow,
       bottom color=blue] (0,0) rectangle (2\paperwidth+3cm,2cm);}}
\begin{tikzpicture}[overlay,remember picture]
\begin{scope}
\clip      ([yshift=4cm]current page.west)--++(15:1.2\paperwidth)--++(0,-2cm) --([yshift=2cm]current page.west)--cycle;
\path ([yshift=3cm]current page.west) +(15:0.6\paperwidth) 
node[rotate=15] {\usebox\UlrikeShading};
\end{scope}
\begin{scope}
\clip(current page.west)--++(15:1.2\paperwidth)--++(0,-2cm) --([yshift=-2cm]current page.west)--cycle;
\path ([yshift=-1cm]current page.west) +(15:0.6\paperwidth) 
node[rotate=15] {\usebox\UlrikeShadingB};
\end{scope}    
\end{tikzpicture}
\mbox{}
\end{document}

在此处输入图片描述

PS:我不确定我是否理解您所选择的维度的目的\documentclass{report} \usepackage{tikz} \pgfdeclareverticalshading{titlepage}{...

PPS 对发生的事情进行视觉解释。如果你看看

\documentclass{report}
\usepackage{tikz}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[overlay,remember picture]
\shade[shading=axis,
       top color=yellow,
       bottom color=blue,
       %middle color=red,
       shading angle=30 %????
       ](current page.west)--++(15:1.2\paperwidth)--++(0,-2cm) --([yshift=-2cm]current page.west)--cycle;

\shade[shading=axis,
       top color=yellow,
       bottom color=blue,
       %middle color=red,
       shading angle=30]
([yshift={2cm+sin(15)*1.2\paperwidth}]current page.south west)
rectangle (current page.south east);
\draw ([yshift=2cm]current page.south west)
--++(15:1.2\paperwidth)--++(0,-2cm) --(current page.south west)--cycle;
\end{tikzpicture}
\mbox{}
\end{document}

在此处输入图片描述

然后您会看到得到的结果:由完整矩形的实线包围的区域。阴影角是指完整矩形的阴影角,与您需要的相比,嵌入矩形的尺寸会使其失真。这也解释了为什么您没有获得完整的色谱,只是因为您剪掉了“大图”的一小部分。您可以按照上述方法或使用 来纠正此问题transform canvas,我很乐意将其添加到答案中,但我犹豫了,因为它可能会对其他应用程序造成危害。

相关内容