Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
As is your code seems to be fine to me. Any line that is drawn before the white line gets overwritten. Do you have an example that actually illustrates the problem. –  Peter Grill Jun 15 '11 at 22:05
    
@Peter: I think Nick wants the thick line to not actually be white, but "invisible", so that it doesn't appear against any background, but still has the effect of interrupting lines that were drawn earlier. –  Jake Jun 16 '11 at 0:22
    
@Jake, @Peter: That was the idea, to make the black line I've drawn over it appear as "on top". –  Nick Loughlin Jun 19 '11 at 11:49
add comment

1 Answer

up vote 4 down vote accepted

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}
share|improve this answer
2  
One could make it all self-contained by making the colour selection check to see if beamer was loaded and then set the background colour to the canvas background via the \usebeamercolor{canvas} syntax. –  Andrew Stacey Jun 16 '11 at 6:45
    
@Andrew: I like that. I may also look at trying something more robust using scoping or clipping, in case I ever need to do something over the top of a gradient background, or some other such silliness. –  Nick Loughlin Jun 19 '11 at 11:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.