4

I used the following code to draw multiple double-headed arrows.

When I used one single \draw command, only the last line has double-headed arrow.

But when I used multiple \draw commands, all lines have double-headed arrows. Why was that?

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{verbatim}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{arrows}
\begin{document}
\begin{frame}[t]
\frametitle{}
\begin{tikzpicture}[transform shape]
\draw [ultra thick, blue, latex' -latex'] (0,2) -- +(0:1.2cm) (2,2) -- +(0:1.2cm) (4,2) -- +(0:1.2cm);

\draw [ultra thick, blue, latex' -latex'] (0,1) -- +(0:1.2cm);
\draw [ultra thick, blue, latex' -latex']  (2,1) -- +(0:1.2cm);
\draw [ultra thick, blue, latex' -latex'] (4,1) -- +(0:1.2cm);
\end{tikzpicture}
\end{frame}
\end{document}

enter image description here

  • 2
    If you replace in the first draw command -- by edge, i.e. \draw [ultra thick, blue, latex' -latex'] (0,2) edge +(0:1.2cm) (2,2) edge +(0:1.2cm) (4,2) -- +(0:1.2cm);, you'll get the same result as in the second row, – marmot Oct 27 '18 at 18:32
  • 1
    Thank you very much. Can you please tell me why? – Hany Oct 27 '18 at 18:40
4

If you replace in the first \draw command the first two -- by edge, i.e. \draw [ultra thick, blue, latex' -latex'] (0,2) edge +(0:1.2cm) (2,2) edge +(0:1.2cm) (4,2) -- +(0:1.2cm);, you'll get the same result as in the second row.

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{verbatim}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{arrows}
\begin{document}
\begin{frame}[t]
\frametitle{}
\begin{tikzpicture}[transform shape]
\draw [ultra thick, blue, latex'-latex'] (0,2) edge +(0:1.2cm) (2,2) edge
+(0:1.2cm) (4,2) -- +(0:1.2cm);

\draw [ultra thick, blue, latex' -latex'] (0,1) -- +(0:1.2cm);
\draw [ultra thick, blue, latex' -latex']  (2,1) -- +(0:1.2cm);
\draw [ultra thick, blue, latex' -latex'] (4,1) -- +(0:1.2cm);
\end{tikzpicture}
\end{frame}
\end{document}

enter image description here

The results are different since in the first row of your example you have just one path, and instruct TikZ to insert arrow heads at its start and end. On the other hand, an edge is a new path, so each of these edges will have arrow heads at their start and end positions. I personally do not work with edges that much because I find them slightly confusing. To see that, replace all -- by edges (as I did in the first version of my comment),

\draw [ultra thick, blue, latex'-latex'] (0,2) edge +(0:1.2cm) (2,2) edge +(0:1.2cm) (4,2) edge +(0:1.2cm);

Then you'll get

enter image description here

There is an excess vertical arrow, which you noted yourself. This is because there is essentially an empty path consisting just of one point, (4,2). Why this is the point TikZ takes the path to be, and not, say, (0,2) I do not 100% understand, but this is the reason why I do not like to use edges too much and think your serious of \draw commands is cleaner.

  • @Hany You're welcome! – marmot Oct 27 '18 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.