
Ich habe eine ziemlich einfache Frage:
Gibt es eine einfache Möglichkeit, den folgenden Code anzupassen
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[red, line width = 1mm] (2, 0) -- (-2, 0);
\draw[blue, line width = 1mm] (0, 2) -- (0, -2);
\end{tikzpicture}
\end{document}
so dass die rote Linie vor der blauen liegt und die blaue am Schnittpunkt ein „Loch“ hat. Ohne die Reihenfolge zu ändern, in der sie gezeichnet werden (z. B. die rote zuerst) und ohne die genaue Kenntnis des Schnittpunkts? Im Wesentlichen sollte das Endprodukt ungefähr so aussehen:
Antwort1
In einfachen Fällen sind die Tikz-Optionen double=<color>
und double distance=<dimen>
in Verbindung mit der Tikz-Bibliothek nützlich background
. Siehe das folgende Beispiel.
In komplexen Fällen benötigen Sie möglicherweise knots
ein Paket, wie @Sebastiano inFrage Kommentar.
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}
\draw[white, double=red, double distance=1mm, line width=1mm](2, 0) -- (-2, 0);
\scoped[on background layer]
\draw[blue, line width = 1mm] (0, 2) -- (0, -2);
\end{tikzpicture}
\end{document}
Antwort2
Hier sind einige Möglichkeiten. Alle sind einfach.
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\tikzset{every path/.style={line width=1mm}}
\begin{tikzpicture}
\path
(-1,-1) coordinate (A)
(1,1) coordinate (B)
(-1,1) coordinate (C)
(1,-1) coordinate (D);
\draw[blue] (A)--(B);
\draw[white,line width=2mm] (C)--(D);
\draw[red] (C)--(D);
\end{tikzpicture}
\begin{tikzpicture}
\draw[teal] (A)--(B);
\draw[orange,preaction={draw,line width=2mm,white}] (C)--(D);
\end{tikzpicture}
\begin{tikzpicture}
\path (intersection of A--B and C--D) coordinate (I);
\draw[brown] (A)--(B);
\draw[magenta,shorten >=1mm] (C)--(I);
\draw[magenta,shorten >=1mm] (D)--(I);
\end{tikzpicture}
\begin{tikzpicture}
\path (intersection of A--B and C--D) coordinate (I);
\draw[magenta] (C)--(D);
\path (C)--(I) node[pos=1,sloped,fill=white]{};
\draw[brown] (A)--(B);
\end{tikzpicture}
\begin{tikzpicture} % page 178, PGF manual
\draw[cyan] (A)--(B);
\draw[white,double=red,double distance=1mm] (C)--(D);
\end{tikzpicture}
\end{document}