24

Consider the following example using the angles library and a pic path to mark an angle:

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{angles,decorations.markings}

\begin{document}

\begin{tikzpicture}[
  >=latex,
  decoration={
  markings,
  mark= at position 0.5 with
    {
      \arrow{<}
    }
  }
]

\draw 
  (2,1) coordinate (A) node[label={right:$A$}] {} --
  (0,0) coordinate (B) node[label={left:$B$}] {} --
  (2,-1) coordinate (C) node[label={right:$C$}] {}
  pic[->,draw=red,angle radius=1cm] {angle={C--B--A}}; 
\draw[<-] (3,1) -- (3,-1);   

% The problem is here; pic doesn't seem to obey the decoration
\begin{scope}[yshift=-3cm]
\draw 
  (2,1) coordinate (A) node[label={right:$A$}] {} --
  (0,0) coordinate (B) node[label={left:$B$}] {} --
  (2,-1) coordinate (C) node[label={right:$C$}] {}
  pic[draw=red,angle radius=1cm,postaction=decorate] {angle={C--B--A}};
\draw[postaction=decorate] (3,1) -- (3,-1);   
\end{scope}

\end{tikzpicture}

\end{document}

The result is:

enter image description here

The image on top shows an angle marked using a red arc with an arrow in one end; in the image on the bottom I tried to use a decoration to add the arrow in the middle of the arc, but the postaction=decorate option was ignored; the straight lines to the right are not relevant and are only there for comparison: a simple \draw path obeys the decoration.

What's the proper way to use a decoration for an arc created using the angle pic?

1
  • I used the same code and I got the same result ! Mar 14, 2016 at 6:50

2 Answers 2

7

This went a little too deep than I initially intended to. I can't see how to wrap up the required changes in a coherent patch-y way so I propose to add the postaction=decorate to another location instead of the obvious place that you found out that it won't work.

So if we add

\tikzset{mydeco/.style={pic actions/.append code=\tikzset{postaction=decorate}}}

you would get a handle on controlling the decoration boolean at the right place within \tikz@finish. Otherwise it will always decorate.

\documentclass[tikz,border=10mm]{standalone}
\usetikzlibrary{angles,decorations.markings}

\tikzset{mydeco/.style={pic actions/.append code=\tikzset{postaction=decorate}}}
\begin{document}
\begin{tikzpicture}[
  >=latex,
  decoration={
  markings,
  mark= at position 0.5 with
    {
      \arrow{<}
    }
  }
]

\draw 
  (2,1) coordinate (A) node[label={right:$A$}] {} --
  (0,0) coordinate (B) node[label={left:$B$}] {} --
  (2,-1) coordinate (C) node[label={right:$C$}] {}
  pic[mydeco,draw=red,fill=yellow,angle radius=1cm,pic text=$A$] {angle={C--B--A}};

\end{tikzpicture}
\end{document}

enter image description here

2
  • 1
    By the way, I would consider this as a bug since it can fail in other ways too.
    – percusse
    Aug 1, 2014 at 14:26
  • I used the code given in the doc and I noticed that it is necessary to use a good order for arguments to get a correct result Mar 14, 2016 at 6:54
8

There are two paths used by the angle pic: one to fill the background of the angle and one to draw the arc. And if a pic text is given an additional node will be placed inside the angle. But only the arc path should be decorated.

The arc is drawn by the command \tikz@lib@angle@foreground (see the tikzlibraryangles.code.tex file):

\def\tikz@lib@angle@foreground#1--#2--#3\pgf@stop{%
  \path [name prefix ..] [pic actions, fill=none, shade=none]
  ....
}

You can patch this command using the etoolbox package to add the style myarc as a hook. Then you can pass the decoration to this new style:

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{angles,decorations.markings}

\tikzset{
  myarc/.style={},
  myarc style/.style={myarc/.append style={#1}}}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\tikz@lib@angle@foreground}{shade=none}{shade=none, myarc}{}{}
\makeatother

\begin{document}
\begin{tikzpicture}[
    >=latex,
    decoration={
      markings,
      mark= at position 0.5 with{\arrow{<}}
    }
  ]

  \draw 
    (2,1) coordinate (A) node[label={right:$A$}] {} --
    (0,0) coordinate (B) node[label={left:$B$}] {} --
    (2,-1) coordinate (C) node[label={right:$C$}] {}
    pic[->,draw=red,angle radius=1cm] {angle={C--B--A}}; 
  \draw[<-] (3,1) -- (3,-1);

  \begin{scope}[yshift=-3cm]
  \draw 
    (2,1) coordinate (A) node[label={right:$A$}] {} --
    (0,0) coordinate (B) node[label={left:$B$}] {} --
    (2,-1) coordinate (C) node[label={right:$C$}] {}
    pic[draw=red,angle radius=1cm,myarc style={postaction=decorate}] {angle={C--B--A}};
  \draw[postaction=decorate] (3,1) -- (3,-1);   
  \end{scope}

\end{tikzpicture}
\end{document}

enter image description here

Note that pos=0.5 anchors the end of the arrow midway. Because of < this is the wide end of the arrow in the example.

1
  • Yes, this is a possible solution. Aug 1, 2014 at 0:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .