3

Is it possible to specify an arrow tip for one end of a path without overriding an existing specification for the other end?

I have noticed that this can be achieved (at least, at the end--but not the start--of a path, and using an older version of pgf?) by using an invalid arrow end type, but of course this gives an error. Is there an arrow shape that says "use the current default arrowhead or lack thereof", giving this behavior?

\documentclass[tikz, border=2pt]{standalone}
\begin{document}
\tikzset{arrowstart/.style={<-initial}}
\begin{tikzpicture}
  \begin{scope}[->]
    \draw[arrowstart] (0,.2) -- +(1,0);
  \end{scope}
  \begin{scope}[|-|]
    \draw[arrowstart] (0,0) -- +(1,0);
  \end{scope}
  \draw[arrowstart] (0,-.2) -- +(1,0);
\end{tikzpicture}
\end{document}

should produce:

arrows

(Of course, if I know what the arrow at the other end should be then I can use the correct specification, but if I want to use the same style in several different scopes then this may not be practical.)

3
  • perhaps \begin{scope}[->] \draw[<-] (0,1) -- (1,1); \end{scope} \begin{scope} \draw[<-] (0,0) -- (1,0); \end{scope}, where the top arrow should be of <-> type and the bottom <- with the same foo in \draw [foo] in either case would make a clearer MWE/specification.
    – Dai Bowen
    Oct 31, 2016 at 20:30
  • 1
    Probably you wan to set both arrow ends using /.tip in this way you can inherit it. For example if you set in the scope [>/.tip={}, </.tip=latex, <-] then you can use stealth-> that will behave like stealth-.
    – Kpym
    Oct 31, 2016 at 20:56
  • @Kpym: Ah, thanks! Of course, that basically means I have to set all of my arrow tips that way, but it works! At least for single arrow tips. Is there a way to apply it for composite arrow tips like >|?
    – Emma
    Oct 31, 2016 at 21:23

1 Answer 1

2

I don't know a way to recover the current arrow, but you can define your initial arrow as empty by default, and redefine it in the scope.

\documentclass[tikz, border=2pt]{standalone}
\tikzset{
  initial/.tip = {},
  arrowstart/.style={<-initial}
}
\begin{document}
  \begin{tikzpicture}
    \begin{scope}[initial/.tip = {latex}, -initial, yshift=4mm]
      \draw[red] (0,2mm) -- +(1,0);
      \draw[arrowstart] (0,0) -- +(1,0);
    \end{scope}
    \begin{scope}[initial/.tip = {|}, initial-initial]
      \draw[red] (0,2mm) -- +(1,0);
      \draw[arrowstart] (0,0) -- +(1,0);
    \end{scope}
    \begin{scope}[yshift=-4mm]
      \draw[red] (0,2mm) -- +(1,0);
      \draw[arrowstart] (0,0) -- +(1,0);
    \end{scope}
  \end{tikzpicture}
\end{document}

enter image description here

1
  • Wonderful, thanks! Even better to define separate arrowhead and arrowtail tip styles (initially empty), with the entire picture using arrowtail-arrowhead. Then the two styles can be set independently throughout.
    – Emma
    Oct 31, 2016 at 22:18

You must log in to answer this question.

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