对于矩形区域,可以这样:
\documentclass[tightpage]{standalone}
\usepackage{varwidth}
\usepackage{tikz}
\usetikzlibrary{backgrounds,patterns,calc}
\begin{document}
\def\yysep{0.42}
\def\xxsep{7.3}
\begin{tikzpicture}
\foreach \y in {1,...,4} {%
\node[inner sep=0pt] (l\y) at (0,\yysep*\y) {};
\node[inner sep=0pt] (r\y) at (\xxsep,\yysep*\y) {};
};
\coordinate (O) at (0,2.5*\yysep);
\draw[dashed] (O) -- ++(\xxsep,0);
\begin{pgfonlayer}{background}
\draw[fill=green!20] (l1) rectangle (r4);
\end{pgfonlayer}
\coordinate (auxa) at ($(l1)!0.5!(r1)$);
\coordinate (auxb) at ($(l1)!0.5!(l4)$);
\coordinate (boxcenter) at (auxa |- auxb);
\begin{scope}
\pgfsetfillpattern{crosshatch dots}{red}
\fill (l1) -- (boxcenter) -- (r1) -- cycle;
\fill (l4) -- (boxcenter) -- (r4) -- cycle;
\end{scope}
\draw[very thick] (l1) rectangle (r4);
\end{tikzpicture}
\end{document}
但对于曲线区域,这怎么可能呢?
\documentclass{standalone}
\usepackage{varwidth}
\usepackage{tikz}
\usetikzlibrary{backgrounds,patterns,calc}
\usepackage{xparse}
\begin{document}
\begin{tikzpicture} [scale=2]
\filldraw [thick, fill=green!20] (120:2cm) arc [start angle = 120, end angle=60, radius=2cm] --++(60:0.5cm) arc [start angle=60, end angle=120, radius=2.5cm] --++(120:-0.5cm);
\begin{scope}
\pgfsetfillpattern{dots}{red}
% \fill (120:2.5cm) arc [start angle = 120, end angle=60, radius=2.5cm] to[out=165,in=10] (90:2.25)to[out=160,in=10] (120:2.5) ;
\end{scope}
\end{tikzpicture}
\end{document}
答案1
不确定您想要如何填充,因为您的矩形示例并未填满整个区域。
\documentclass{standalone}
\usepackage{varwidth}
\usepackage{tikz}
\usetikzlibrary{backgrounds,patterns,calc}
\usepackage{xparse}
\begin{document}
\begin{tikzpicture} [scale=2]
\filldraw [thick,fill=green!20] (120:2cm) arc [start angle = 120, end angle=60, radius=2cm] --++ (60:0.5cm) arc [start angle=60, end angle=120, radius=2.5cm] --++(120:-0.5cm);
\begin{scope}
\pgfsetfillpattern{dots}{red}
\filldraw (0,2.25) to [bend right =10] ((120:2.5cm) arc [start angle = 120, end angle=60, radius=2.5cm]
to [bend right=10] cycle;
\filldraw (0,2.25) to [bend right =20] ((120:2cm) arc [start angle = 120, end angle=60, radius=2cm]
to [bend right=20] cycle;
\end{scope}
\end{tikzpicture}
\end{document}
(请注意,在运行您的示例之前,我必须删除许多 unicode RTL 控制字符)