58

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

2 Answers 2

86

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
    Dec 25, 2011 at 9:00
  • 4
    And if you add ->-/.default=0.5 at the first definition, it's practically perfect! Thanks!
    – Rmano
    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
    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 .