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?
2 Answers
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);
-
3
-
4And if you add
->-/.default=0.5
at the first definition, it's practically perfect! Thanks!– RmanoDec 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. Apr 25, 2017 at 17:46
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}
\usetikzlibrary{decorations.markings}
see the pagraph "Arrow Tip Markings" in the pgfmanual or look at some examples in several answers here.