TeX - LaTeX Asked on August 30, 2021
The backgrounds
tikz library defines framed
(a.k.a. show background rectangle
) which draws a background rectangle.
Now, when we have a picture that involves different layers (say, a background
and a main
layer), we wouldd like the frame of the picture to be drawn on the deeper layer (background
in our case), or even deeper. However, it seems that the frame is shown on the main
layer.
This MWE contains a single node on the background layer in a framed picture. The background rectangle fills the main
layer, and therefore the node is not visible anymore.
documentclass{article}
usepackage{tikz}
usetikzlibrary{backgrounds}
tikzset{background rectangle/.style={fill=blue!5}}
pgfdeclarelayer{background}
pgfsetlayers{background, main}
begin{document}
begin{tikzpicture}[framed]
begin{pgfonlayer}{background}
node {Hello world};
end{pgfonlayer}
end{tikzpicture}
end{document}
Note: I know that I could reorder the layers to let the main at the bottom (like main
, background
, mymain
), but if I can avoid to surround the important parts of the picture with a mymain
layer, that would be better.
(I'd kind of taken it for granted that the backgrounds
library defines a layer called background
...) You are entirely correct that the library defines a background
layer, the first thing it does is
pgfdeclarelayer{background}%
pgfsetlayers{background,main}%
So for your case it might make more sense to declare a middle
layer, and do pgfsetlayers{background,middle, main}
.
documentclass[border=5mm]{standalone}
usepackage{tikz}
usetikzlibrary{backgrounds}
tikzset{background rectangle/.style={fill=blue!25}}
pgfdeclarelayer{middle}
pgfsetlayers{background,middle, main}
begin{document}
begin{tikzpicture}[framed]
node [fill=blue] {hello};
begin{pgfonlayer}{middle}
node {Hello world};
end{pgfonlayer}
end{tikzpicture}
end{document}
Correct answer by Torbjørn T. on August 30, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP