2本の線を交差させる

2本の線を交差させる

かなり単純な質問があります。

次のコードを簡単に適応させる方法はありますか?

\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}

赤い線が青い線の前にあり、青い線の交差点に「穴」があるように。描画順序を変更せず (たとえば、赤い線を最初にする)、交差点を正確に把握せずに、最終的な製品は次のようになります。

ここに画像の説明を入力してください

答え1

単純なケースでは、 tikz ライブラリ とともにtikz オプションdouble=<color>とが役立ちます。次の例を参照してください。double distance=<dimen>background

複雑なケースでは、knots@Sebastianoが提案したようにパッケージが必要になる場合があります。質問コメント

\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}

ここに画像の説明を入力してください

答え2

ここにいくつかの方法があります。どれも簡単です。

ここに画像の説明を入力してください

\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}

関連情報