设置:在 beamer 中使用 Tikz。
我想用颜色填充由一些线段和一个圆界定的区域。由于我无法\clip
与路径一起使用,我四处寻找并找到了这个替代解决方案使用 PGf 图\fillbetween
。
在 MWE 的右侧部分(见下图),一切都如我所愿。然而,在左侧部分,圆圈内有一个白色三角形区域,我希望用灰色填充。我试着尝试了解图层如何与剪辑一起工作,但我却更加困惑了。
可能相关:
- 这个问题看起来确实相关,但我不确定我的路径是否从另一个地方开始。感觉更像是以某种方式翻译的。但即使是同样的问题,我也不知道如何将那里的解决方案应用于我的情况。
\documentclass{standalone} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=1.10} \usepgfplotslibrary{fillbetween} \begin{document} \begin{tikzpicture} \pgfdeclarelayer{pre main} \pgfsetlayers{pre main,main} \coordinate (1) at (-4.7,4.5); \coordinate (2) at (-3.2,4.1); \coordinate (a) at (-4.9,2.3); %\coordinate (a) at (-4,2.3); %%%%change (a) causes even stranger behaviour \coordinate (c) at (-6.9,8.7); \coordinate (e) at (-2.7,8.8); \coordinate (f) at (-4.5,2.3); \coordinate (g) at (2.9,6.2); \clip (-7,2) rectangle (-1.5,5); %edges \draw [name path=D] (a)-- (c); \draw [name path=E] (f)-- (e); \draw [name path=A] (f)-- (g); %dots \draw [fill=black] (1) circle (2.5pt); \draw [fill=black] (2) circle (2.5pt); %circles \pgfonlayer{pre main} \begin{scope} \clip[insert path={(1) circle (1cm)}]; %%%%remove the clip gives impression that the path is translated \tikzfillbetween[of=E and D]{gray}; \end{scope} \begin{scope} \clip[insert path={(2) circle (1cm)}]; \tikzfillbetween[of=A and E]{gray}; \end{scope} \endpgfonlayer \end{tikzpicture} \end{document}
提前致谢!
答案1
不带和层的建议\fillbetween
:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (1) at (-4.7,4.5);
\coordinate (2) at (-3.2,4.1);
\coordinate (a) at (-4.9,2.3);
%\coordinate (a) at (-4,2.3);
\coordinate (c) at (-6.9,8.7);
\coordinate (e) at (-2.7,8.8);
\coordinate (f) at (-4.5,2.3);
\coordinate (g) at (2.9,6.2);
\clip (-7,2) rectangle (-1.5,5);
%circles
\begin{scope}
\clip (1) circle [radius=1];
\fill[gray](a)--(c)--(e)--(f)--cycle ;
\end{scope}
\begin{scope}
\clip (2) circle [radius=1];
\fill[gray](e)--(f)--(g)--cycle;
\end{scope}
%edges
\draw (a)-- (c) (f)-- (e) (f)-- (g);
%dots
\draw [fill=black] (1) circle [radius=2.5pt];
\draw [fill=black] (2) circle [radius=2.5pt];
\end{tikzpicture}
\end{document}
或者
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (1) at (-4.7,4.5);
\coordinate (2) at (-3.2,4.1);
\coordinate (a) at (-4.9,2.3);
%\coordinate (a) at (-4,2.3);
\coordinate (c) at (-6.9,8.7);
\coordinate (e) at (-2.7,8.8);
\coordinate (f) at (-4.5,2.3);
\coordinate (g) at (2.9,6.2);
\clip (-7,2) rectangle (-1.5,5);
%circles
\path
[path picture={\fill[gray] (1) circle [radius=1];}]
(a)--(c)--(e)--(f)--cycle ;
\path
[path picture={\fill[gray] (2) circle [radius=1];}]
(e)--(f)--(g)--cycle ;
%edges
\draw (a)-- (c) (f)--(e) (f)--(g);
%dots
\foreach \c in {1,2}
{\draw [fill=black] (\c) circle [radius=2.5pt];}
\end{tikzpicture}
\end{document}
还有一个使用图层的建议:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\pgfdeclarelayer{pre main}
\pgfsetlayers{pre main,main}
\coordinate (1) at (-4.7,4.5);
\coordinate (2) at (-3.2,4.1);
\coordinate (a) at (-4.9,2.3);
%\coordinate (a) at (-4,2.3);
\coordinate (c) at (-6.9,8.7);
\coordinate (e) at (-2.7,8.8);
\coordinate (f) at (-4.5,2.3);
\coordinate (g) at (2.9,6.2);
\clip (-7,2) rectangle (-1.5,5);
%edges
\draw (a)-- (c) (f)--(e) (f)--(g);
%dots
\foreach \c in {1,2}
{\draw [fill=black] (\c) circle [radius=2.5pt];}
%circles
\pgfonlayer{pre main}
\path
[path picture={\fill[gray] (1) circle [radius=1];}]
(a)--(c)--(e)--(f)--cycle ;
\path
[path picture={\fill[gray] (2) circle [radius=1];}]
(e)--(f)--(g)--cycle ;
\endpgfonlayer
\end{tikzpicture}
\end{document}