TikZ:苍白效应

TikZ:苍白效应
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns}

\def\cHeight{0.5}
\def\cWidth{4}
\newcommand{\cigarOne}[2]{
    \pgfmathtruncatemacro\result{\cWidth/2}
    \filldraw[pattern=north east lines] (#1,#2) rectangle (\result+#1,#2-\cHeight);
    \filldraw[pattern=crosshatch dots] (\result+#1,#2) rectangle (#1+\cWidth,#2-\cHeight);
}

\begin{document}
\begin{tikzpicture}
    \cigarOne{2}{5};
\end{tikzpicture}
\end{document}

该命令cigarOne定义了两个填充的矩形,我希望其中一个(左边的矩形)是“苍白的”,几乎看不见的矩形。

答案1

是不是这样的:

\documentclass{standalone}
\usepackage{tikz,pgf}
\usetikzlibrary{patterns}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
%---------------------------------------------------------
\def\cHeight{0.5}
\def\cWidth{4}
\newcommand{\cigarOne}[2]{
    \pgfmathtruncatemacro\result{\cWidth/2}
    \filldraw[draw=black!10,pattern=north east lines,pattern color=black!10] (#1,#2) rectangle (\result+#1,#2-\cHeight);
    \filldraw[pattern=crosshatch dots] (\result+#1,#2) rectangle (#1+\cWidth,#2-\cHeight);
}
%---------------------------------------------------------
\begin{document}
\begin{tikzpicture}
    \cigarOne{2}{5};
\end{tikzpicture}
%---------------------------------------------------------
\end{document}  

在此处输入图片描述

相关内容