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.

Possible Duplicate:
“Z-level” in TikZ

When using layers in tikz I usually do the following:

\begin{pgfonlayer}{background}
    \draw[red] (0,0)--(1,0);
\end{pgfonlayer}

Is there a way of using the layers inline? e.g.:

\draw[layer=background, red] (0,0) -- (1,0);
share|improve this question

marked as duplicate by Loop Space, Joseph Wright Jan 5 '12 at 22:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

up vote 2 down vote accepted

I don’t know a way for this. My workaround is creating new commands for layers:

\documentclass{minimal}

\usepackage{tikz}
    \pgfdeclarelayer{background}
    \pgfsetlayers{main,foreground}
    \newcommand{\onlayer}[2]{%
        \begin{pgfonlayer}{#1}%
        #2%
        \end{pgfonlayer}%
    }
    \newcommand{\bglayer}[1]{%
        \begin{pgfonlayer}{background}%
        #1%
        \end{pgfonlayer}%
    }

\begin{document}
\begin{tikzpicture}
    \fill (0,0) rectangle (2,2);
    \bglayer{\fill [gray] (1,1) rectangle (3,3);}
\end{tikzpicture}
\end{document}

It’s not as comfortable as your inline version but better (shorter) than using the pgfonlayer environment …

Edit Another way is shown in "Z-level" in TikZ

share|improve this answer
    
Accepted because of "Another way is shown in "Z-level" in TikZ" –  romeovs Jan 2 '12 at 10:17

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