Documentation/TikZ & Graphics/How to Add Labels on Arrows in TikZ
TikZ & Graphics

How to Add Labels on Arrows in TikZ

Labels on arrows are essential for annotating relationships in flowcharts, state machines, and network diagrams. TikZ provides several ways to position text along edges — above, below, at specific positions, sloped to follow the line, or placed at any fraction of the path. This tutorial covers all the common patterns you'll need. Bibby AI's instant preview makes it easy to fine-tune label positions visually, saving you the constant recompile cycles you'd face on Overleaf.

Position Labels Above, Below, and Beside Arrows

Use the node command inline with \draw to place labels at various positions along an edge:

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

\begin{document}
\begin{tikzpicture}[
    node distance=3.5cm,
    box/.style={draw, rectangle, minimum width=1.5cm, minimum height=0.8cm},
    >={Stealth[length=2.5mm]}
]
    \node[box] (A) {A};
    \node[box, right=of A] (B) {B};
    \node[box, below=2.5cm of A] (C) {C};
    \node[box, below=2.5cm of B] (D) {D};

    % Label positions
    \draw[->] (A) -- node[above] {above} (B);
    \draw[->] (A) -- node[left]  {left} (C);
    \draw[->] (B) -- node[right] {right} (D);
    \draw[->] (C) -- node[below] {below} (D);

    % Labels at specific positions along the path
    \draw[->, dashed] (A) -- node[pos=0.3, above left] {30\%} 
                             node[pos=0.7, below right] {70\%} (D);
\end{tikzpicture}
\end{document}

Use Sloped and Auto-Positioned Labels

Make labels follow the angle of diagonal arrows with sloped, and use auto-placement for cleaner layouts:

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

\begin{document}
\begin{tikzpicture}[
    node distance=3cm,
    vertex/.style={draw, circle, fill=blue!15, minimum size=0.8cm},
    >={Stealth[length=2.5mm]}
]
    \node[vertex] (A) at (0,0) {A};
    \node[vertex] (B) at (4,2) {B};
    \node[vertex] (C) at (4,-2) {C};
    \node[vertex] (D) at (8,0) {D};

    % Sloped labels follow the edge angle
    \draw[->] (A) -- node[sloped, above] {data flow} (B);
    \draw[->] (A) -- node[sloped, below] {error path} (C);

    % Auto placement: 'auto' puts label on the side away from center
    \draw[->] (B) -- node[auto] {process} (D);
    \draw[->] (C) -- node[auto, swap] {recover} (D);

    % Styled label with background
    \draw[->, thick, red] (A) to[bend left=20]
        node[midway, above, fill=yellow!30, font=\scriptsize\bfseries, inner sep=2pt] 
        {critical} (D);
\end{tikzpicture}
\end{document}

Label Curved Arrows and Multi-Segment Paths

Add labels to curved arrows (bend), right-angle paths (|-), and multi-segment connections:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning, calc}

\begin{document}
\begin{tikzpicture}[
    box/.style={draw, rounded corners, minimum width=2cm, minimum height=0.7cm, font=\small},
    >={Stealth[length=2.5mm]}
]
    \node[box] (A) at (0,0) {Start};
    \node[box] (B) at (5,0) {Middle};
    \node[box] (C) at (5,-3) {End};

    % Label on curved arrow
    \draw[->, bend left=25] (A) to node[above] {yes} (B);
    \draw[->, bend right=25] (A) to node[below] {no} (B);

    % Label on right-angle path
    \draw[->] (A) |- node[pos=0.25, left] {step 1} 
                      node[pos=0.75, above] {step 2} (C);

    % Label on vertical segment
    \draw[->] (B) -- node[right, align=left, font=\scriptsize] 
        {validate\\transform\\save} (C);
\end{tikzpicture}
\end{document}

💡 Tips

  • Use pos=0.5 (the default) for midpoint labels, or any value from 0 (start) to 1 (end) for custom positioning.
  • The sloped option is essential for diagonal edges — without it, labels render horizontally which looks odd.
  • Add fill=white or fill=yellow!20 to label nodes so they have a visible background when crossing other edges.
  • Use 'auto' and 'auto, swap' on graphs with many edges to automatically avoid label overlaps.

Try This in Bibby AI

Write LaTeX faster with AI auto-complete and instant compilation.

Start Writing Free

Related Tutorials

How to Add Labels on Arrows in TikZ | Bibby AI