Tx · LaTeX & TikZ

How to Bend Arrows in XY-pic

Published By the 9to5Science editorial team

At a glance

  1. 1. Load XY-pic

    Add the XY-pic package to your LaTeX preamble.

  2. 2. Add a curve modifier

    Place @/^/ or @/_/ immediately after \ar and before the direction.

  3. 3. Set the bend size

    Add a distance inside the modifier when the default curve is not suitable.

  4. 4. Add labels

    Put labels after the direction, using ^ for above and _ for below.

Advertisement

XY-pic bends arrows with curve modifiers placed in the arrow command. The common forms @/^/ and @/_/ curve an arrow to opposite sides of its path. The example below draws two curved arrows from the same node to another and shows how to set their labels and curvature.

Minimal working example

The package option [all] loads the XY-pic features used by the example. Compile this as a complete LaTeX file:

\documentclass{article}
\usepackage[all]{xy}

\begin{document}
\[
\xymatrix{
  A \ar@/^/[r]^{f} \ar@/_/[r]_{g} & B
}
\]
\end{document}

The \xymatrix environment creates a diagram with nodes A and B. In \ar@/^/[r]^{f}, \ar starts an arrow, @/^/ bends it, and [r] sets its direction to the right. The ^{f} places the label on the upper side of the arrow. The second command uses @/_/ to bend the arrow the other way and _{g} to put its label below.

Change the bend direction and size

For arrows running from left to right, @/^/ bends upward and @/_/ bends downward. You can specify a distance between the slashes to make the curve more or less pronounced:

\ar@/^1pc/[r]
\ar@/_1pc/[r]

Here 1pc is the bend distance. A larger distance generally makes the curve more pronounced; a smaller distance makes it flatter. Try values such as 0.5pc or 2pc and adjust until the diagram is readable. The default form without a distance is often sufficient for a small diagram.

The modifier belongs between \ar and the direction in brackets. For example, \ar@/^/[r] is the curved version of \ar[r]. If the diagram has arrows in different directions, check the rendered result: the curve is relative to the arrow’s path, so its visual side may not correspond to the page’s top or bottom in the same way as it does for a left-to-right arrow.

Curving arrows versus separating them

If two arrows share the same endpoints, bending them in opposite directions is a clear way to distinguish them. For example:

\xymatrix{
  A \ar@/^/[r]^{f} \ar@/_/[r]_{g} & B
}

If you want two arrows to remain straight but not overlap, use a parallel shift rather than a curve. XY-pic’s @<...> modifier shifts an arrow away from its usual position; for instance, \ar@<1ex>[r] offsets a rightward arrow. This is different from @/^/, which changes the arrow’s path into a curve.

Common mistakes

  • Putting the modifier after the direction: Use \ar@/^/[r], not \ar[r]@/^/. Keep the modifier in the arrow command before [r].
  • Leaving out the slashes: The curve syntax includes both delimiting slashes, as in @/^/ or @/^1pc/.
  • Using the wrong package: The example uses XY-pic, loaded by \usepackage[all]{xy}. It is not the same syntax as the tikz-cd package.
  • Expecting a curve from a shift: @<1ex> offsets an arrow; it does not create the same curved path as @/^/.
  • Forgetting math mode: Put \xymatrix in math mode, as in the displayed example, or inside another appropriate math environment.

If the curved arrows still overlap, increase the bend distance or adjust the label positions. For more complicated diagrams, separating parallel arrows with a small shift can be more legible than using a very large curve.

References

  1. The XY-pic User's Guide

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