是否可以tikz
绘制一个带阴影的矩形,其中阴影颜色(不是填充颜色)具有渐变(从一侧的红色变为另一侧的蓝色)?
\draw[pattern=crosshatch, pattern color=lightgray] (0,0) rectangle (10,5);
如何为图案颜色添加渐变?
答案1
只是一个想法,声明一个与期望结果相反的模式,并在postaction
渐变色区域内使用它。
以下代码声明了一个mycheckerboard
模式(灵感来自原始checkerboard
模式)。它填充小方块(2mmx2mm),并在它们之间留出 1mm 的空间。用于后置操作模拟 1mm 宽度的交叉线。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{patterns}
% Checkerboards
\pgfdeclarepatternformonly
{mycheckerboard}%name
{\pgfpointorigin}% lower left point
{\pgfqpoint{6mm}{6mm}}% upper right point
{\pgfqpoint{6mm}{6mm}}% tile size
{% shape description
\pgfpathrectangle{\pgfqpoint{.5mm}{.5mm}}{\pgfqpoint{2mm}{2mm}}
\pgfpathrectangle{\pgfqpoint{3.5mm}{.5mm}}{\pgfqpoint{2mm}{2mm}}
\pgfpathrectangle{\pgfqpoint{.5mm}{3.5mm}}{\pgfqpoint{2mm}{2mm}}
\pgfpathrectangle{\pgfqpoint{3.5mm}{3.5mm}}{\pgfqpoint{2mm}{2mm}}
\pgfusepath{fill}
}
\begin{document}
\begin{tikzpicture}
\fill[left color=red, right color=yellow, postaction={pattern=mycheckerboard, pattern color=white}] (0,0) rectangle (10,5);
\end{tikzpicture}
\begin{tikzpicture}
\fill[postaction={pattern=mycheckerboard, pattern color=white}, top color=blue, bottom color=green] (0,0) circle (3cm);
\end{tikzpicture}
\end{document}
答案2
您可以像下面这样在矩形下方放置一个阴影框。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\shade [left color=red, right color=blue, ] (0,0) rectangle (10,5);
\draw [pattern=crosshatch, pattern color=lightgray, ] (0,0) rectangle (10,5);
\end{tikzpicture}
\end{document}