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?
[Tex/LaTex] Tikz: Arrowheads in the center
arrowspositioningtikz-pgf
Related Solutions
I have prepared a comprehensive set of arrow tips matching the Computer Modern arrows, and posted it on CTAN (along with some discussion on this issue and some more stuff that might be useful for mathematical diagrams).
My arrow tips are not as precise as Christian's, but they are about as good as one can get using a few line strokes (as opposed to filling a region), and in practice I find the result good enough.
Here is a comparison (Computer Modern above, tikz-drawn arrow below).
\documentclass{article}
\usepackage{tikz,tikz-cd,graphicx}
\begin{document}
\noindent\hspace{2mm} \scalebox{20}{$\hookrightarrow$}
\vspace{2cm}
\tikz \draw[line width=8pt,cm right hook-cm to] (0,0) to (7,0);
\end{document}
Adapting Qrrbrbirlbels answer from here: https://tex.stackexchange.com/a/131325/10995
You will want to use it like
\draw plot ... [arrow inside={end=stealth,opt={scale=2}}{0.25,0.5,0.75}];
It is important, to place it after the plot part, because else you will get Dimension too large
errors, which emerge from an incompatibility between smooth
and decorate
. The first argument of arrow inside
accepts the keys end
and opt
; in end=...
you put the arrow tip, in opt={...}
you can put any arrow tip options. The second argument to arrow inside
is a list of positions between 0
and 1
where you want the markings to be placed.
Implementation
\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{decorations.markings}
\tikzset{
set arrow inside/.code={\pgfqkeys{/tikz/arrow inside}{#1}},
set arrow inside={end/.initial=>, opt/.initial=},
/pgf/decoration/Mark/.style={
mark/.expanded=at position #1 with
{
\noexpand\arrow[\pgfkeysvalueof{/tikz/arrow inside/opt}]{\pgfkeysvalueof{/tikz/arrow inside/end}}
}
},
arrow inside/.style 2 args={
set arrow inside={#1},
postaction={
decorate,decoration={
markings,Mark/.list={#2}
}
}
},
}
\begin{document}
\begin{tikzpicture}
\begin{scope}[scale=2]
\node[label=below:$A$] (A) at (0,0) {};
\node[label=below:$B$] (B) at (2,0.25){};
\draw[blue] plot [smooth,tension=1]
coordinates {(A) (1,0) (1.14,-0.6) (0.5,-0.5) (0.5,0.5) (1.5,0) (B)}
[arrow inside={end=stealth,opt={red,scale=2}}{0.25,0.5,0.75}];
\end{scope}
\draw [fill=black] (A) circle (1pt);
\draw [fill=black] (B) circle (1pt);
\end{tikzpicture}
\end{document}
Output
Alternatively you can draw an arrow at the end of each line segment using the on each segment
style as defined here: https://tex.stackexchange.com/a/69225/10995
You need the bending
library (from TikZ 3.0.0) to use the [bend]
option for the arrows, because else the arrow will modify the path's tension such that the original path and the path redrawn using on each segment
will visibly differ. Of course you still apply color, etc. to the arrows. It seems, though, that scale
is not possible.
Implementation
\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{decorations.pathreplacing,bending}
\makeatletter
\tikzset{
on each segment/.style={
decorate,
decoration={
show path construction,
moveto code={},
lineto code={
\path [#1]
(\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
},
curveto code={
\path [#1] (\tikzinputsegmentfirst)
.. controls
(\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
..
(\tikzinputsegmentlast);
},
closepath code={
\path [#1]
(\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
},
},
},
}
\makeatother
\begin{document}
\clearpage
\begin{tikzpicture}
\begin{scope}[scale=2]
\node[label=below:$A$] (A) at (0,0) {};
\node[label=below:$B$] (B) at (2,0.25){};
\draw[blue] plot [smooth,tension=1]
coordinates {(A) (1,0) (1.14,-0.6) (0.5,-0.5) (0.5,0.5) (1.5,0) (B)}
[postaction={on each segment={draw,-{stealth[red,bend]}}}];
\end{scope}
\draw [fill=black] (A) circle (1pt);
\draw [fill=black] (B) circle (1pt);
\end{tikzpicture}
\end{document}
Best Answer
Perhaps you prefer this kind of syntax :
If you only want an arrow in the middle of a path, you can write
And the you just need to write :