59

For arrows I have gone through options like ->, ->>, <-, <<- but havent found one for making the arrowhead appear in the center of the line of the curve (something like ->-) How do I do it in TIkz?

3
  • 3
    With the library \usetikzlibrary{decorations.markings} see the pagraph "Arrow Tip Markings" in the pgfmanual or look at some examples in several answers here. Commented Dec 25, 2011 at 7:39
  • 1
    Not exactly the same, but I asked a question a while ago about drawing an arrow head in the middle of an ellipse: tex.stackexchange.com/questions/1260/… but I have found the syntax a bit unwieldy.
    – bryn
    Commented Dec 25, 2011 at 7:57
  • 1
    A possible duplicate of tex.stackexchange.com/questions/3161/…. Commented Jul 11, 2014 at 13:27

2 Answers 2

88

Perhaps you prefer this kind of syntax :

\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}

\begin{document}
\tikzset{->-/.style={decoration={
  markings,
  mark=at position #1 with {\arrow{>}}},postaction={decorate}}}

\begin{tikzpicture}
 \draw[->-=.5] (0,0) to [bend left] (2,4);
 \draw[->-=.8] (0,0) to [bend right] (2,4);
\end{tikzpicture}

\end{document} 

If you only want an arrow in the middle of a path, you can write

\tikzset{->-/.style={decoration={
  markings,
  mark=at position .5 with {\arrow{>}}},postaction={decorate}}}

And the you just need to write :

 \draw[->-] (0,0) to [bend left] (2,4);

enter image description here

3
  • 3
    Aha, that's a neat syntax!
    – percusse
    Commented Dec 25, 2011 at 9:00
  • 4
    And if you add ->-/.default=0.5 at the first definition, it's practically perfect! Thanks!
    – Rmano
    Commented Dec 15, 2015 at 11:31
  • Is it possible to modify this so that \draw[->-] (0,0) -- (1,0) -- (1,1) -- (0,1) -- cylce; would create a square such that there is an arrowhead on every edge? With the code at hand this unfortunately leads to a path where there is only 1 arrowhead at the middle of the total path length.
    – Hyperplane
    Commented Apr 25, 2017 at 17:46
38

You can define a new line style and decorate it. (as Altermundus commented and also given in this answer)

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}

\tikzset{middlearrow/.style={
        decoration={markings,
            mark= at position 0.5 with {\arrow{#1}} ,
        },
        postaction={decorate}
    }
}

\begin{tikzpicture}
\draw[middlearrow={<}] (0,0) -- (20:2);
\draw[middlearrow={>}] (0,0) -- (40:2);
\draw[middlearrow={|}] (0,0) -- (60:2);
\draw[middlearrow={stealth reversed}] (0,0) -- (80:2);
\draw[middlearrow={latex}] (0,0) arc (50:-40:-1.5);
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

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