Tx · LaTeX & TikZ

How to Draw a TikZ Arrow with Heads at Both Ends

Published By the 9to5Science editorial team

At a glance

  1. 1. Use the double-arrow option

    Add <-> to the options of a TikZ draw command to put an arrowhead at each end.

  2. 2. Choose the endpoints

    Write the coordinates or nodes on either side of -- to define the arrow's path.

  3. 3. Customize if needed

    Load arrows.meta to select a different arrowhead style, such as Stealth.

To draw a line with an arrowhead at each end in TikZ, put <-> in the path’s options. The two arrowheads point in opposite directions along the path, one at its start and one at its end.

Here is a complete minimal example you can compile:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
  \draw[<->] (0,0) -- (4,0);
\end{tikzpicture}

\end{document}

The tikz package provides the drawing commands, and (0,0) -- (4,0) defines the line segment. The <-> option requests arrowheads at both ends.

Add arrowheads at both ends

The general form is:

\draw[<->] (start) -- (end);

Replace (start) and (end) with coordinates or node names. For example, a vertical double-headed arrow is:

\draw[<->] (0,0) -- (0,3);

The arrowhead at the starting point points back along the path; the arrowhead at the ending point points forward. If you want a one-way arrow instead, use -> for a head at the end or <- for a head at the start.

You can combine the double-arrow option with other TikZ path options. For instance, this draws a red, dashed double-headed arrow:

\draw[<->, red, dashed] (0,0) -- (4,0);

Use a custom arrowhead style

The basic <-> form uses TikZ’s default arrow tips. To choose a different tip, load the arrows.meta library and specify the start and end tips explicitly:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\begin{document}

\begin{tikzpicture}
  \draw[{Stealth}-{Stealth}] (0,0) -- (4,0);
\end{tikzpicture}

\end{document}

In {Stealth}-{Stealth}, the first tip specification is for the start of the path and the second is for its end. You can choose different tips at each end if that is useful, such as {Bar[width=3pt]}-{Stealth}. The arrows.meta library provides the named tip styles and options for adjusting their appearance.

Put the arrow between nodes

A double-headed arrow can connect named nodes just as it can connect coordinates. For example:

\begin{tikzpicture}
  \node (left) at (0,0) {Left};
  \node (right) at (4,0) {Right};
  \draw[<->] (left) -- (right);
\end{tikzpicture}

If the arrow should meet the edges of the nodes rather than pass through their centers, use anchors. For nodes placed horizontally, (left.east) and (right.west) select the facing edges:

\draw[<->] (left.east) -- (right.west);

TikZ also calculates suitable boundary points when you connect nodes without specifying anchors, but explicit anchors give you more control over where the line meets each node.

Common mistakes

  • Using -> when you need two heads. -> puts a head only at the end. Use <-> for heads at both ends.
  • Putting the option in the wrong place. Write the option after \draw, as in \draw[<->] ...;.
  • Forgetting the library for named tips. The custom Stealth tip in arrows.meta requires \usetikzlibrary{arrows.meta} in the preamble. The basic <-> option does not.
  • Confusing an arrow with two heads and two separate arrows. <-> creates one path with a tip at each end; it does not draw two parallel lines.

References

  1. The TikZ and PGF Packages: Manual for Version 3.1.11a

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.