问题:在下图中,如何为标记为“此处”的区域添加阴影?
我猜测通过该intersections
库可以找到一个优雅的解决方案,但我对它不够熟悉。
这是我的 LaTeX 代码的一个最小工作示例:
\documentclass[crop]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[thin,dashed,<->] (0.5,0) to (7.5,0);
\coordinate (a) at (1,0);
\coordinate (b) at (3,0);
\coordinate (c) at (5,0);
\coordinate (d) at (7,0);
\draw (a) to[bend left=80] (c);
\draw (b) to[bend left=80] (d);
\node (x) at (4,0.3) {\small here};
\end{tikzpicture}
\end{document}
我不需要“这里”这个词,它只是用来指向我想要阴影的区域。
答案1
\begin{tikzpicture}
\draw[thin,dashed,<->] (0.5,0) to (7.5,0);
\coordinate (a) at (1,0);
\coordinate (b) at (3,0);
\coordinate (c) at (5,0);
\coordinate (d) at (7,0);
\draw (a) to[bend left=80] (c);
\draw (b) to[bend left=80] (d);
\clip (a) to [bend left=80] (c) -- cycle;
\fill[yellow] (b) to[bend left=80] (d) -- cycle;
\node (x) at (4,0.3) {\small here};
\end{tikzpicture}
更新
在上述解决方案中,由于裁剪,黄色区域的右边缘较薄。如果绘制圆弧,则可以解决此问题后scope
黄色填充。绘制弧线时,需要使用“撤消”剪切:
\begin{tikzpicture}
\draw[thin,dashed,<->] (0.5,0) to (7.5,0);
\coordinate (a) at (1,0);
\coordinate (b) at (3,0);
\coordinate (c) at (5,0);
\coordinate (d) at (7,0);
\begin{scope}
\clip (a) to [bend left=80] (c) -- cycle;
\fill[yellow] (b) to[bend left=80] (d) -- cycle;
\end{scope}
\draw (a) to[bend left=80] (c);
\draw (b) to[bend left=80] (d);
\node (x) at (4,0.3) {\small here};
\end{tikzpicture}
更新 2:看,妈妈,没有剪辑!
当然,这是大欺骗。只是为了好玩。
\begin{tikzpicture}
\draw[thin,dashed,<->] (0.5,0) to (7.5,0);
\coordinate (a) at (1,0);
\coordinate (b) at (3,0);
\coordinate (c) at (5,0);
\coordinate (d) at (7,0);
\fill[yellow]
(a) to[bend left=80] (c);
\fill[white, even odd rule]
(a) to[bend left=80] (c) -- (b) to[bend left=80] (d);
\draw (a) to[bend left=80] (c);
\draw (b) to[bend left=80] (d);
\node (x) at (4,0.3) {\small here};
\end{tikzpicture}
答案2
嗯,这仍然是作弊行为,但我想也没那么糟糕。您可以限制绘图范围以保持剪辑局部化。
\documentclass[crop,tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[thin,dashed,<->] (0.5,0) to (7.5,0);
\coordinate (a) at (1,0);
\coordinate (b) at (3,0);
\coordinate (c) at (5,0);
\coordinate (d) at (7,0);
\draw (a) to[bend left=80] (c);
\clip[preaction={draw}] (b) to[bend left=80] (d);
\node (x) at (4,0.3) {};
\shade (a) to[bend left=80] (c);
\end{tikzpicture}
\end{document}