Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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.

share|improve this answer
    
Yes, this is a possible solution. –  Gonzalo Medina Aug 1 at 0:04

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

share|improve this answer
1  
By the way, I would consider this as a bug since it can fail in other ways too. –  percusse Aug 1 at 14:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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