TikZ Can I draw an arrow by specifying the initial point, direction, and length?
You can use the the show path construction
and the markings
decoration to put an arrow next to every path segment. The limitations are that you have to repeat the last point in the path (-- cycle
alone won't do it) and you have to take care of the direction in which you draw the path.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}[
parallel arrows/.style={
postaction=decorate,
decoration={
show path construction,
lineto code={
\path[
postaction=decorate,
decoration={
markings,
mark=at position .5 with {
\draw[red,-stealth] (-.5,.1) -- (.5,.1);
}
}
] (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
}
}
}
]
\draw[parallel arrows] (-6,-3) -- (0,-3) -- (-4,0) -- (-6,-3) -- cycle;
\draw[parallel arrows] (0,-3) -- (6,-3) -- (2,0) -- (0,-3) -- cycle;
\path[parallel arrows] (-4,0) -- (0,-3) -- (2,0) -- (-4,0) -- cycle;
\draw[parallel arrows] (-4,0) -- (2,0) -- (-2,3) -- (-4,0) -- cycle;
\end{tikzpicture}
\end{document}
Here is a version that modifies the to path
. So you need to replace --
by to
, and to apply the style, e.g.
\draw[pft] (-6, -3) to (0, -3) to (-4,0) to cycle;
The to path
is modified in such a way that a sloped arrow (from the shapes.arrows
library) is attached in the middle of the path. allow upside down
is used to avoid that TikZ intelligently rotates the arrows in a way that is appropriate for texts. I also would use symbolic coordinates, and the nodes can be placed in the centers of the triangles with barycentric cs:
.
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{shapes.arrows}
\begin{document}
\begin{tikzpicture}[pft/.style={to path={--(\tikztotarget)
node[midway,above=0.6em,marrow,allow upside down]{}}},
marrow/.style={sloped,fill, minimum height=3cm, single arrow, single arrow
head extend=.5cm, single arrow head indent=.25cm,xscale=0.3,yscale=0.15}]
\path (-6, -3) coordinate (A) (6, -3) coordinate (B) (-2, 3) coordinate (C)
(A) -- (B) coordinate[midway] (AB) (B) -- (C) coordinate[midway] (BC)
(C) -- (A) coordinate[midway] (CA);
\draw[pft] (A) to (AB) to (CA) to cycle
(AB) to (B) to (BC) to cycle
(CA) to (BC) to (C) to cycle
(CA) to (AB) to (BC) to cycle;
\path (barycentric cs:A=1,AB=1,CA=1) node{$T_1^{(1)}$}
(barycentric cs:AB=1,BC=1,CA=1) node{$T_2^{(1)}$}
(barycentric cs:CA=1,BC=1,C=1) node{$T_3^{(1)}$}
(barycentric cs:B=1,AB=1,BC=1) node{$T_4^{(1)}$};
\end{tikzpicture}
\end{document}