I am trying to use tikz to draw a quiver and I need to draw arrows of the form =-> and -=> between two nodes. What is the best way to do it? Any help is appreciated.
3 Answers
Is this close to what you want?
\documentclass[tikz, border=5pt]{standalone}
\usetikzlibrary{decorations.pathreplacing, arrows}
\tikzset{
-z>/.style={
decoration={
show path construction,
lineto code={
\path (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast) coordinate[pos=#1] (mid);
\draw (\tikzinputsegmentfirst) -- (mid);
\draw[double, -implies] (mid) -- (\tikzinputsegmentlast); }
},decorate
}, -z>/.default=.5,
z->/.style={
decoration={
show path construction,
lineto code={
\path (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast) coordinate[pos=#1] (mid);
\draw[double] (\tikzinputsegmentfirst) -- (mid);
\draw[->] (mid) -- (\tikzinputsegmentlast);
}
},decorate
}, z->/.default=.5,
}
\begin{document}
\begin{tikzpicture}
\draw [-z>] (0,0) -- (1,0);
\begin{scope}[red, thick]
\draw [z->=.3] (0,-.2) -- (1,-.4);
\end{scope}
\end{tikzpicture}
\end{document}
I don't think you can have =
as part of a style name, so I've denoted a double line with z
. Note that the arrowheads aren't quite the same for the two styles, although this can probably be fixed. For some reason, styles directly on the \draw
commands don't get reliably passed to the decorations, but if you need to style it further you can use a scope.
You can do something like this, which uses an edge
to draw the second line with the arrow tip.
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (1,0) edge [double, -{Implies}] ++(10pt,0);
\draw [double] (0,-.25) -- (1,-.25) edge [double=none, ->] ++(10pt,0);
\end{tikzpicture}
\end{document}
But I'm not convinced I understand what you're trying to do.
-
Thanks a lot! It almost does what I want, except I need the transition between the single line to the double line happen right at the middle of the edge, and instead of specifying the transition point I would like to only specify the end points of the line...– DapsOct 17, 2016 at 2:00
-
Just make the
edge
smaller e.g. use5pt
rather than10pt
which will be the same as if you did the switch halfway along the edge. It would not be easy to create this in a way that required only specifying the end points and was at all convenient to use. It's certainly possible, but you need an expert ;).– cfrOct 17, 2016 at 2:50
You can use the midway
key (or pos
key) to coordinate
or node
to find the midpoint of an edge, and then draw the two halves, or redraw the double half on top of the single half. Here are some basic examples of doing this. (Note that cfr's use of the arrows.meta tikz library would produce better arrowheads.)
\documentclass[tikz,border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[black!10] (-1,0) grid (3,3);
\path (0,0) node (A)[draw,circle] {A} -- (3,1) node[draw,circle](B){B} (A)--(B) coordinate[midway](mAB);
\path (A) -- (-1,2) node[draw,circle] (C) {C} (A)--(C) coordinate[pos=0.5](mAC);
\draw[double,line cap=round] (A)--(mAB); \draw[->] (mAB)--(B);
\draw (A)--(mAC); \draw[double,->] (mAC)--(C);
\draw[thick] (3,3)coordinate(A)--(1,1)coordinate(Z) coordinate[midway](M); \draw[double,->] (M)--(Z);
\end{tikzpicture}
\end{document}
arrows.meta
. Take a look.edge
for the second part so it is all done in one\path
or\draw
command.