1

I am using the angles library to label angles in my diagrams. I'm noticing, however, that the arc created by the angles package rests on a layer above the rest of the diagram by default, i.e., the following MWE produces the picture below it and to the left.

\documentclass[border=2mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{angles}

\begin{document}


\begin{tikzpicture}
    \draw [red,thick]
        (0,0) coordinate (B) --
        (2,0) coordinate (A) --
        (2,1.2) coordinate (C) pic[pic text={$\theta$},draw,black,ultra thick,angle radius=8mm,angle eccentricity=1.2]{angle} --
        cycle
    ;
\end{tikzpicture}


\end{document}

enter image description here enter image description here

I would like to produce a picture where the arc lies on a lower layer (as in the picture above and to the right). As I understand it, this should be possible by adding the behind path key to the optional parameters describing the pic (the behind path key does work on my computer with both nodes and pics outside of the angles library, so I'm pretty sure it's just a problem with angles). However, this has no effect. What's up with this behavior, and what modification to the optional parameters describing the pic will produce the intended result?

Note that the following MWE produces the desired result (the picture above and to the right) using the backgrounds library and a scope. I am asking, though, how to avoid using this construct (or, I suppose, drawing a second red triangle on top of the original, or any other forced construct).

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{angles,backgrounds}
\begin{document}

\begin{tikzpicture}
    \draw [red,thick]
        (0,0) coordinate (B) --
        (2,0) coordinate (A) --
        (2,1.2) coordinate (C) --
        cycle
    ;
    \begin{scope}[on background layer]
        \pic[pic text={$\theta$},draw,ultra thick,angle radius=8mm,angle eccentricity=1.2]{angle};
    \end{scope}
\end{tikzpicture}

\end{document}

Thanks!

  • Indeed, page 568 of the 3.1.5b manual states that drawings are made in front of the path. I quote Concerning the sector that makes up the drawing of the angle, the angular part of this sector is drawn in front of the path if the draw option is given to the pic, while filled sector is drawn behind the pic, provided an option like fill or shade is passed to the pic. – AndréC Jun 30 at 22:23
  • from the manual version 3.1.5b, page 225: Note that behind path only applies to the current path; not to the current scope or picture. So the problem is the red triangle drawn before is NOT the current path when you draw the angle symbol. – Black Mild Jun 30 at 23:03
2

the angles library explicitly puts some part of the code in the background and some other the foreground. You could write your own pic based on the code:

\documentclass[border=2mm]{standalone}

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

\makeatletter
\tikzset{
  pics/backangle/.style = {
    setup code  = \tikz@lib@angle@parse#1\pgf@stop,
    background code = \tikz@lib@angle@background#1\pgf@stop\tikz@lib@angle@foreground#1\pgf@stop,
    %foreground code = \tikz@lib@angle@foreground#1\pgf@stop,
  },
  pics/right backangle/.style = {
    setup code  = \tikz@lib@angle@parse#1\pgf@stop,
    background code = \tikz@lib@rightangle@background#1\pgf@stop\tikz@lib@rightangle@foreground#1\pgf@stop,
    %foreground code = \tikz@lib@rightangle@foreground#1\pgf@stop,
  },
  pics/backangle/.default=A--B--C,
}%
\makeatother
\begin{document}


\begin{tikzpicture}
    \draw [red,thick]
        (0,0) coordinate (B) --
        (2,0) coordinate (A) --
        (2,1.2) coordinate (C) pic[pic text={$\theta$},draw,black,ultra thick,angle radius=8mm,angle eccentricity=1.2,]{backangle} --
        cycle
    ;
\end{tikzpicture}


\end{document}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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