Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Modify stacking order of Tikz nodes

1,234 views
Skip to first unread message

Aric Bills

unread,
Sep 4, 2009, 11:56:18 PM9/4/09
to
The following code draws a Tikz matrix and, using the wonderful
Fitting library, draws two filled-in rectangles, one at the bounding
box of nodes (a) and (d), the other at the bounding box of (h) and
(i). I'm grateful I can even do that much, but if possible I'd like
to do even more. The code below will render the bounding box
rectangles on top of the matrix, obscuring the matrix text. If
possible, I would like to change the stacking order so that the
rectangles are on bottom and the matrix on top. If necessary, I
suppose I could create copies of the relevant nodes that would sit on
top of the whole stack, but I'd rather not do that if there's a more
elegant method. Any ideas?

Thanks,
Aric

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{fit}

\begin{document}

\begin{tikzpicture}
\matrix [nodes={anchor=base}] {
\node (a) {a}; & \node (b) {b}; & \node (c) {c}; \\
\node (d) {d}; & \node (e) {e}; & \node (f) {f}; \\
\node (g) {g}; & \node (h) {h}; & \node (i) {i}; \\
};

\node [inner sep=0pt,opacity=0.8,fill=blue,fit=(a) (d)] {};
\node [inner sep=0pt,opacity=0.8,fill=blue,fit=(h) (i)] {};
\end{tikzpicture}

\end{document}

Peter Ullrich

unread,
Sep 5, 2009, 1:37:45 AM9/5/09
to
as far as I know TikZ supports layers.
you may search the documentation for usages of the background layer.
also
http://www.texample.net/tikz/examples/feature/layers/
may help?

Alain Matthes

unread,
Sep 5, 2009, 2:27:28 AM9/5/09
to

perhaps like this

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{fit,backgrounds}

\begin{document}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\begin{tikzpicture}


\matrix [nodes={anchor=base}] {
\node (a) {a}; & \node (b) {b}; & \node (c) {c}; \\
\node (d) {d}; & \node (e) {e}; & \node (f) {f}; \\
\node (g) {g}; & \node (h) {h}; & \node (i) {i}; \\
};

\begin{pgfonlayer}{background}
\node [inner sep=0pt,fill=blue!50,fit=(a) (d)] {};
\node [inner sep=0pt,fill=blue!50,fit=(h) (i)] {};
\end{pgfonlayer}
\end{tikzpicture}

\end{document}

Best Regards

Alain Matthes

Aric

unread,
Sep 5, 2009, 4:57:13 PM9/5/09
to
On 5 sep, 00:27, Alain Matthes <alain.matt...@nofree.fr> wrote:

Peter and Alain,

Thank you both. This code does just what I need.

Aric

0 new messages