0

I would like to use the double -latex arrow style in a whole scope.

When I define a simple style myarrow plain which only sets red color the scope style is applied in \begin{scope}[myarrow plain] \draw ... \end{scope} and I don't have to say \draw[myarrow plain]: plain explicit and plain scope in the image.

For myarrow complex style, which entails double -latex, the scope only changes foreground color (complex scope below) and I have to say \draw[myarrow complex] to have the double arrow (complex explicit).

Can I get an explanation how to declare the myarrow complex style correcetly so that the scope uses it? I am guessing it has to do with postaction, or appending vs. defining to style, but I know too little about TikZ internals (so far).

\documentclass[margin=2mm]{standalone}
\usepackage{tikz} 
\usetikzlibrary{arrows}
% https://tex.stackexchange.com/a/72793
\tikzset{
  double -latex/.style args={#1 colored by #2 and #3}{    
    -latex,line width=#1,#2,
    postaction={draw,-latex,#3,line width=(#1)/3,shorten <=(#1)/4,shorten >=4.5*(#1)/3},
  }
}
\tikzset{
    myarrow complex/.style={line width=2mm,double -latex=2mm colored by brown and red},
    myarrow plain/.style={-latex,color=red}
}
\begin{document}
\begin{tikzpicture}
    \begin{scope}[myarrow complex]
        \draw (0,1) to node[pos=.5,below]{complex scope} (4,1);
        \draw[myarrow complex] (0,0) to node[pos=.5,below]{complex explicit} (4,0);
    \end{scope}
    \begin{scope}[myarrow plain]
        \draw[myarrow plain] (0,3) to node[pos=.5,below]{plain explicit} (4,3);
        \draw (0,2) to node[pos=.5,below]{plain scope} (4,2);
    \end{scope}
\end{tikzpicture}
\end{document}

PDF

1 Answer 1

1

P. 187 in the manual about preaction and postaction

...this option only has an effect when given to a \path or as part of the options of a node; as an option to a {scope} it has no effect.

If you want the postaction to be applied to every path in the scope, you can use every path/.style. To stop a recursive runaway. you can use nomorepostaction from

https://tex.stackexchange.com/a/5354/8650

like this:

\documentclass[tikz, border=1cm]{standalone}
\makeatletter
\tikzset{nomorepostaction/.code=\let\tikz@postactions\pgfutil@empty}
\makeatother
\tikzset{
double -latex/.style args={#1 colored by #2 and #3}{    
-latex, line width=#1, #2,
every path/.style={postaction={nomorepostaction, draw, -latex, #3, line width=(#1)/3, shorten <=(#1)/4, shorten >=4.5*(#1)/3}}
}}
\tikzset{
myarrow complex/.style={line width=2mm, double -latex=2mm colored by brown and red},
myarrow plain/.style={-latex, color=red}
}
\begin{document}
\begin{tikzpicture}
\begin{scope}[myarrow complex]
\draw (0,1) to node[pos=.5, below]{complex scope} (4,1);
\draw[myarrow complex] (0,0) to node[pos=.5, below]{complex explicit} (4,0);
\end{scope}
\end{tikzpicture}
\end{document}

Two brown arrows with red center

1
  • I appreciate your explanation and example. I figured in the end I will have to go explicit, since in the real document, there is more than just arrows in the scope, and applying the style to them (nodes with frames) will change other things, and (as it seems) kill postactions for other styles as well... Not asking for a clean solution from you, just saying it works only in limited circumstances, which was the original question :)
    – eudoxos
    Commented Oct 19, 2022 at 8:54

You must log in to answer this question.

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