如何使用 TikZpicture 用图案填充封闭曲线?

如何使用 TikZpicture 用图案填充封闭曲线?

我正在学习如何将 tikzpicture 与 latex 结合使用。我在网上找不到用阴影图案填充封闭曲线的解决方案。这是我的代码:

\documentclass{article}
\usepackage{amssymb,amsmath}
\usepackage{bm}
\usepackage{tikz,pgfplots}
\usepackage{graphicx}% Include figure files
\usetikzlibrary{decorations.markings}
\usepackage{subfig}
\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,positioning,fit,petri}
\usetikzlibrary{decorations.pathreplacing} % LATEX and plain TEX when using Tik Z
\usetikzlibrary{decorations.markings} % LATEX and plain TEX when using Tik Z
\usetikzlibrary{decorations.shapes} % LATEX and plain TEX when using Tik Z
\usetikzlibrary{arrows.meta} % LATEX and plain TEX when using Tik Z
\usetikzlibrary{quotes,angles} % Drawing angles using the PG 3.0 angles and quotes libraries
\usetikzlibrary{positioning}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns} % LATEX and plain TEX when using Tik Z
\usetikzlibrary{patterns,chains}
\usetikzlibrary{hobby}
\usepackage{tikz-3dplot}
\usepackage{esvect} % use for arrow over character
\newcommand{\uvec}[1]{\boldsymbol{\hat{\textbf{#1}}}}
\pgfplotsset{compat=1.16}
\begin{document}
%
%
\begin{tikzpicture}
%         
%
\coordinate (N) at (8.5,10);
\coordinate (O) at (5.9,5.5);
\coordinate (P) at (6.6,5.4);
\coordinate (Q) at (7.6,6);
\coordinate (R) at (8.4,6.3);
\coordinate (S) at (8.1,7);
\coordinate (T) at (7.4,6.9);
\coordinate (U) at (6.4,6.6);
\draw (O) to [pattern=north east lines, closed, curve through = {(O) (P)  (Q)  (R) (S)  (T) (U)}] (O);
%
%
% The above draws my 'blob' OK. But I want it filled with pattern.
%
%
%
filldraw (O) to [draw=blue, color=blue, fill=blue!20,  closed, curve through = {(O) (P)  (Q)  (R) (S)  (T) (U)}] (O);
%
%
% The above simply fills it with black.
%
%
%
\end{tikzpicture}
\end{document}

您有什么建议吗?谢谢。

答案1

只需添加一些选项即可。在本例中,添加pattern=...。如果您想要颜色,请添加pattern color=...

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,positioning,fit,petri}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{decorations.shapes}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{quotes,angles}
\usetikzlibrary{positioning}
\usetikzlibrary{patterns} 
\usetikzlibrary{chains}
\usetikzlibrary{hobby}
\begin{document}
\begin{tikzpicture}
\coordinate (N) at (8.5,10);
\coordinate (O) at (5.9,5.5);
\coordinate (P) at (6.6,5.4);
\coordinate (Q) at (7.6,6);
\coordinate (R) at (8.4,6.3);
\coordinate (S) at (8.1,7);
\coordinate (T) at (7.4,6.9);
\coordinate (U) at (6.4,6.6);
\draw[pattern=horizontal lines] (O) to [pattern=north east lines, closed, curve through = {(O) (P)  (Q)  (R) (S)  (T) (U)}] (O);
\end{tikzpicture}
\end{document}

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,positioning,fit,petri}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{decorations.shapes}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{quotes,angles}
\usetikzlibrary{positioning}
\usetikzlibrary{patterns} 
\usetikzlibrary{chains}
\usetikzlibrary{hobby}
\begin{document}
\begin{tikzpicture}
\coordinate (N) at (8.5,10);
\coordinate (O) at (5.9,5.5);
\coordinate (P) at (6.6,5.4);
\coordinate (Q) at (7.6,6);
\coordinate (R) at (8.4,6.3);
\coordinate (S) at (8.1,7);
\coordinate (T) at (7.4,6.9);
\coordinate (U) at (6.4,6.6);
\draw[pattern=horizontal lines,pattern color=red] (O) to [pattern=north east lines, closed, curve through = {(O) (P)  (Q)  (R) (S)  (T) (U)}] (O);
\end{tikzpicture}
\end{document}

在此处输入图片描述

更多信息请阅读 Ti 718 页Z 手册。

答案2

pattern您在 中有 ,to但需要在draw选项中包含它。我还从序言中删除了不必要的内容。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{hobby,patterns}
\begin{document}
\begin{tikzpicture}
 \coordinate (N) at (8.5,10);
 \coordinate (O) at (5.9,5.5);
 \coordinate (P) at (6.6,5.4);
 \coordinate (Q) at (7.6,6);
 \coordinate (R) at (8.4,6.3);
 \coordinate (S) at (8.1,7);
 \coordinate (T) at (7.4,6.9);
 \coordinate (U) at (6.4,6.6);
 \draw[pattern=north east lines] (O) to [ closed, curve through = {(P)  (Q)  (R) (S)  (T) (U)}] (O);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容