[Tex/LaTex] Drawing line “on top” in tikz

tikz-pgf

I have a tikz graphic which I'm using in two different final documents. It contains a line-crossing where I've needed to specify which line was on-top, via surrounding it with a white-coloured "buffer", akin to breaking a line when drawing a braid for example. For more details see/compile my code at the bottom.

One of these documents is a plain-paper article which has a white background (no problem); the other is a beamer presentation, which for the sake of my audience's eyes I've tinted the background a light blue to reduce the contrast to a confortable level.

The white space around my line is unfortunately visible as an area of white against the background in the beamer. Is there some option to pass to an object to make it overwrite everything it wanders over as invisible?

Here's the promised code.

\documentclass{amsart}
\usepackage{tikz}
\begin{document}
\scalebox{9}{\begin{tikzpicture}
\fill[blue!20] (0,0) rectangle (1,1);
\draw[line width=2pt] (1,1) -- (0,0) -- (1,-1);
\draw[white,line width = 5pt] (0,1) -- (1,0) -- (0,-1);
\draw[line width=2pt] (0,1) -- (1,0) -- (0,-1);
\end{tikzpicture}}
\end{document}

Best Answer

As far as I know, this is not possible. I guess the simplest solution is to give the background color a name (e.g. via \colorlet{bgcolor}{white}) and use that for the overdrawing. Since you are only using one background color per document you don't have to change color in the middle of a path anyway (which is impossible/very hard to do).

preactions and defining options can save you some typing:

\documentclass{amsart}
\usepackage{tikz}
\colorlet{bgcolor}{white}

\tikzset{
    overdraw/.style={preaction={draw,bgcolor,line width=#1}},
    overdraw/.default=5pt
}


\begin{document}
\scalebox{9}{\begin{tikzpicture}
    {% temporally change the background color
    \colorlet{bgcolor}{blue!20}
    \fill[bgcolor] (0,0) rectangle (1,1);
    \draw[line width=2pt] (1,1) -- (0,0) -- (1,-1);
    \draw[line width=2pt,overdraw] (0,1) -- (1,0);
    }
    \draw[line width=2pt,overdraw=10pt] (1,0) -- (0,-1);
\end{tikzpicture}}
\end{document}