我正在绘制一些交叉线,其中一些线被背景中的粗灰线强调。现在,我想在线条交叉处留出间隙,我可以通过反向剪辑来实现这一点,但问题是生成的 PDF 似乎渲染起来有点沉重。我将在 Keynote (OS X) 中使用 PDF,在较新的版本中,渲染更复杂的 PDF 真的很慢。(也欢迎提供解决该问题的提示,但可能与此处的主题无关。我在渲染图像或电影方面取得了一些成功,但这并不令人满意……)
首先,该版本仅使用白线表示间隙——这是一种显然不起作用的常见技术:
\begin{tikzpicture}[draw=solarized-blue]
\pts
\draw[line width=3pt,black!15] (a) -- (b);
\draw[thick] (a) -- (b);
\draw[ultra thick, white] (x) -- (y);
\draw[thick] (x) -- (y);
\end{tikzpicture}
这是我当前的解决方案,当我的 PDF 中有超过几行内容时,某些查看器(或者至少是 Keynote,也许还有其他 Quartz 应用程序)在渲染时会遇到一些麻烦:
\begin{tikzpicture}[draw=solarized-blue]
\pts
\draw[line width=3pt,black!15] (a) -- (b);
\begin{scope}[even odd rule]
\draw[thick] (x) -- (y);
\clip[overlay]
(-1cm,-1cm) rectangle (1cm,1cm)
($(x)!0.8pt!90:(y)$) -- ($(y)!0.8pt!-90:(x)$) --
($(y)!0.8pt!90:(x)$) -- ($(x)!0.8pt!-90:(y)$) --
cycle;
\draw[thick] (a) -- (b);
\end{scope}
\end{tikzpicture}
我尝试过一种替代解决方案,使用透明度,并将“背景”线放在顶部——但这样我就必须调整主线本身的颜色。在这里我只是添加了一些白色,但我想我真的必须减少黑色的数量。此外,它会弄乱交叉线的颜色,所以这实际上不起作用:
\begin{tikzpicture}[draw=solarized-blue]
\pts
\draw[thick,draw=solarized-blue!85!white] (a) -- (b);
\draw[ultra thick, white] (x) -- (y);
\draw[thick] (x) -- (y);
\draw[line width=3pt,black,opacity=.15] (a) -- (b);
\end{tikzpicture}
\end{document}
是否有任何干净的方法可以做到这一点而不导致过于复杂的剪切路径或类似情况?
完整文档:
\documentclass[tikz,border=3pt]{standalone}
\usepackage{tikz,xcolor-solarized}
\usetikzlibrary{calc}
\def\pts{\path (-10pt,-10pt) coordinate (a)
(+10pt,+10pt) coordinate (b)
(+10pt,-10pt) coordinate (x)
(-10pt,+10pt) coordinate (y);}
\begin{document}
\begin{tikzpicture}[draw=solarized-blue]
\pts
\draw[line width=3pt,black!15] (a) -- (b);
\draw[thick] (a) -- (b);
\draw[ultra thick, white] (x) -- (y);
\draw[thick] (x) -- (y);
\end{tikzpicture}
\begin{tikzpicture}[draw=solarized-blue]
\pts
\draw[line width=3pt,black!15] (a) -- (b);
\begin{scope}[even odd rule]
\draw[thick] (x) -- (y);
\clip[overlay]
(-1cm,-1cm) rectangle (1cm,1cm)
($(x)!0.8pt!90:(y)$) -- ($(y)!0.8pt!-90:(x)$) --
($(y)!0.8pt!90:(x)$) -- ($(x)!0.8pt!-90:(y)$) --
cycle;
\draw[thick] (a) -- (b);
\end{scope}
\end{tikzpicture}
\begin{tikzpicture}[draw=solarized-blue]
\pts
\draw[thick,draw=solarized-blue!85!white] (a) -- (b);
\draw[ultra thick, white] (x) -- (y);
\draw[thick] (x) -- (y);
\draw[line width=3pt,black,opacity=.15] (a) -- (b);
\end{tikzpicture}
\end{document}
答案1
这是一个老问题但值得回答。
您可以通过在每个交叉点处填充小圆圈来切割双曲线。
\documentclass[tikz,border=3pt]{standalone}
\usetikzlibrary{intersections}
\colorlet{front}{blue!70}
\colorlet{back}{gray!30}
\begin{document}
\begin{tikzpicture}[x=2cm,y=2cm]
\clip (-2,-2) rectangle (2,2);
\def\pathA{(-2,-1) .. controls (8,-1) and (-8,1) .. (2,1)}
\def\pathB{(-1,-2) .. controls (-1,8) and (1,-8) .. (1,2)}
% draw the curve A with two colors : back and front
\draw[name path=curveA, line width=10pt, back] \pathA;
\draw[line width=3pt,front] \pathA;
\path[name path=curveB] \pathB;
% draw a circle at each intersection with back color to "cut" the curve
\fill [name intersections={of=curveA and curveB, name=i, total=\t}, back]
foreach \s in {1,...,\t}{(i-\s) circle (5pt)};
% draw the curve B through the cuted curve A
\draw [line width=3pt, front] \pathB;
\end{tikzpicture}
\end{document}