TransWikia.com

What are the scoping rules for options set on the background layer (with the backgrounds package)?

TeX - LaTeX Asked on April 21, 2021

As illustrated by the pictures below, some options appear not to be constrained by their scope (e.g., line thickness and dashing) while others do. (Using the backgrounds package.) What is the rule? Separately, note the odd consequences for the arrowhead size.

documentclass{article}
usepackage{tikz}
usetikzlibrary{backgrounds}
begin{document}

begin{tikzpicture}[x=1in,y=1in]
draw[ultra thick,blue] (0,1) -- (2,1);
begin{scope}[on background layer]
draw (0,2) -- (2,0);
end{scope}
begin{scope}[on background layer={ultra thick,red,dashed,->,>=latex}]
draw (0,0) -- (2,2);
end{scope}
end{tikzpicture}
%
begin{tikzpicture}[x=1in,y=1in]
draw[ultra thick,blue] (0,1) -- (2,1);
begin{scope}[on background layer={red,dashed,ultra thick}]
draw (0,0) -- (2,2);
end{scope}
begin{scope}[on background layer={->,>=latex}]
draw (0,2) -- (2,0);
end{scope}
end{tikzpicture} 
end{document} 

questionOfScope

One Answer

enter image description here

documentclass{article}
usepackage{tikz}
usetikzlibrary{backgrounds}
begin{document}
    
    begin{tikzpicture}[x=1in,y=1in]
        draw[ultra thick,blue] (0,1) -- (2,1);
        begin{scope}[on background layer]
            draw (0,2) -- (2,0);
        end{scope}
        begin{scope}[on background layer={ultra thick,red,dashed,->,>=latex}]
            draw (0,0) -- (2,2);
        end{scope}
    end{tikzpicture}
    %
    begin{tikzpicture}[x=1in,y=1in]
        draw[ultra thick,blue] (0,1) -- (2,1);
        begin{scope}[on background layer={red,dashed,ultra thick}]
            draw (0,0) -- (2,2);
        end{scope}
        begin{scope}[on background layer={ultra thick,dashed,->,>=latex}]
            draw (0,2) -- (2,0);
        end{scope}
    end{tikzpicture} 
end{document} 

Answered by js bibra on April 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP