带阴影的图案填充

带阴影的图案填充

我想要一个带有阴影的矩形。此外,阴影应该有一些阴影。但是,我只能在背景中获得颜色的过渡。有人知道如何在只有白色背景的阴影中只使用颜色渐变吗?

多谢。

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture} 
\fill[left color=blue!40, right color=white, postaction={pattern=north west lines, pattern color=blue!40}] (0,0) rectangle (3,3);
\end{tikzpicture}
\end{document}

答案1

只是为了好玩!

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\def\a{3}
\def\lw{0.2}
\draw[blue, thick] (0,0) rectangle (\a,\a);
\foreach \x [count=\i] in{0,0.1,0.2,...,\a}{
\draw [blue,line width=\lw mm,opacity=\i/45](\x,0)--(0,\x) (\a,\a-\x)--(\a-\x,\a);}
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

这在概念上与Ignasi 的精彩回答因为图案是背景颜色,所以它决定了哪些部分应该保留为非阴影部分。为了自定义图案,我使用这个答案。当然,您需要拨打电话shading angle以使阴影遵循东北线。

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{patterns}
% defining the new dimensions and parameters
\newlength{\hatchspread}
\newlength{\hatchthickness}
\newlength{\hatchshift}
\newcommand{\hatchcolor}{}
% declaring the keys in tikz
\tikzset{hatchspread/.code={\setlength{\hatchspread}{#1}},
         hatchthickness/.code={\setlength{\hatchthickness}{#1}},
         hatchshift/.code={\setlength{\hatchshift}{#1}},% must be >= 0
         hatchcolor/.code={\renewcommand{\hatchcolor}{#1}}}
% setting the default values
\tikzset{hatchspread=3pt,
         hatchthickness=0.4pt,
         hatchshift=0pt,% must be >= 0
         hatchcolor=black}
% declaring the pattern
\pgfdeclarepatternformonly[\hatchspread,\hatchthickness,\hatchshift,\hatchcolor]% variables
   {custom north west lines}% name
   {\pgfqpoint{\dimexpr-2\hatchthickness}{\dimexpr-2\hatchthickness}}% lower left corner
   {\pgfqpoint{\dimexpr\hatchspread+2\hatchthickness}{\dimexpr\hatchspread+2\hatchthickness}}% upper right corner
   {\pgfqpoint{\dimexpr\hatchspread}{\dimexpr\hatchspread}}% tile size
   {% shape description
    \pgfsetlinewidth{\hatchthickness}
    \pgfpathmoveto{\pgfqpoint{-1.5\hatchthickness}{\dimexpr1.5\hatchthickness+\hatchspread+\hatchshift}}
    \pgfpathlineto{\pgfqpoint{\dimexpr\hatchspread+1pt+\hatchshift}{-1pt}}
    \ifdim \hatchshift > 0pt
      \pgfpathmoveto{\pgfqpoint{0pt}{\hatchshift}}
      \pgfpathlineto{\pgfqpoint{\dimexpr1pt+\hatchshift}{-1pt}}
    \fi
    \pgfsetstrokecolor{\hatchcolor}
    \pgfusepath{stroke}
   }

\begin{document}
\begin{tikzpicture} 
\fill[left color=blue!40, right color=white,shading angle=45,line width=2pt,
postaction={pattern=custom north west lines, 
hatchthickness=1pt,hatchcolor=white}] (0,0) rectangle (3,3);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容