From Wikibooks, open books for an open world
Jump to: navigation, search
LaTeX logo.svg


Getting Started
  1. Introduction
  2. Installation
  3. Installing Extra Packages
  4. Basics
  5. How to get help

Common Elements

  1. Document Structure
  2. Text Formatting
  3. Paragraph Formatting
  4. Colors
  5. Fonts
  6. List Structures
  7. Special Characters
  8. Internationalization
  9. Rotations
  10. Tables
  11. Title creation
  12. Page Layout
  13. Customizing Page Headers and Footers‎
  14. Importing Graphics
  15. Floats, Figures and Captions
  16. Footnotes and Margin Notes
  17. Hyperlinks
  18. Labels and Cross-referencing


  1. Errors and Warnings
  2. Lengths
  3. Counters
  4. Boxes
  5. Rules and Struts

Technical Texts

  1. Mathematics
  2. Advanced Mathematics
  3. Theorems
  4. Chemical Graphics
  5. Algorithms
  6. Source Code Listings
  7. Linguistics

Special Pages

  1. Indexing
  2. Glossary
  3. Bibliography Management
  4. More Bibliographies

Special Documents

  1. Scientific Reports (Bachelor Report, Master Thesis, Dissertation)
  2. Letters
  3. Presentations
  4. Teacher's Corner
  5. Curriculum Vitae

Creating Graphics

  1. Introducing Procedural Graphics
  2. MetaPost
  3. Picture
  4. PGF/TikZ
  5. PSTricks
  6. Xy-pic
  7. Creating 3D graphics


  1. Macros
  2. Plain TeX
  3. Creating Packages
  4. Themes


  1. Modular Documents
  2. Collaborative Writing of LaTeX Documents
  3. Export To Other Formats

Help and Recommendations

  1. FAQ
  2. Tips and Tricks


  1. Authors
  2. Links
  3. Package Reference
  4. Sample LaTeX documents
  5. Index
  6. Command Glossary

edit this boxedit the TOC

xy is a special package for drawing diagrams. To use it, simply add the following line to the preamble of your document:


where "all" means you want to load a large standard set of functions from Xy-pic, suitable for developing the kind of diagrams discussed here.

The primary way to draw Xy-pic diagrams is over a matrix-oriented canvas, where each diagram element is placed in a matrix slot:

    \xymatrix{A & B \\
              C & D }

Latex example xypics basic.png

The \xymatrix command must be used in math mode. Here, we specified two lines and two columns. To make this matrix a diagram we just add directed arrows using the \ar command.

    \xymatrix{ A \ar[r] & B \ar[d] \\
               D \ar[u] & C \ar[l] }

Latex example xypics arrows 1.png

The arrow command is placed on the origin cell for the arrow. The arguments are the direction the arrow should point to (up, down, right and left).

        A \ar[d] \ar[dr] \ar[r] & B \\
        D                       & C }

Latex example xypics arrows 2.png

To make diagonals, just use more than one direction. In fact, you can repeat directions to make bigger arrows.

        A \ar[d] \ar[dr] \ar[drr] &   &   \\
        B                         & C & D }

Latex example xypics arrows 3.png

We can draw even more interesting diagrams by adding labels to the arrows. To do this, we use the common superscript and subscript operators.

        A \ar[r]^f \ar[d]_g & B \ar[d]^{g'} \\
        D \ar[r]_{f'}       & C }

Latex example xypics arrows labels.png

As shown, you use these operators as in math mode. The only difference is that that superscript means "on top of the arrow", and subscript means "under the arrow". There is a third operator, the vertical bar: | It causes text to be placed in the arrow.

        A \ar[r]|f \ar[d]|g & B \ar[d]|{g'} \\
        D \ar[r]|{f'}       & C }

Latex example xypics inarrow labels.png

To draw an arrow with a hole in it, use \ar[...]|\hole. In some situations, it is important to distinguish between different types of arrows. This can be done by putting labels on them, or changing their appearance

        \bullet\ar@{->}[rr]     && \bullet\\
        \bullet\ar@{.<}[rr]     && \bullet\\
        \bullet\ar@{~)}[rr]     && \bullet\\
        \bullet\ar@{=(}[rr]     && \bullet\\
        \bullet\ar@{~/}[rr]     && \bullet\\
        \bullet\ar@{^{(}->}[rr] && \bullet\\
        \bullet\ar@2{->}[rr]    && \bullet\\
        \bullet\ar@3{->}[rr]    && \bullet\\
        \bullet\ar@{=+}[rr]     && \bullet }

Latex example xypics arrow list.png

Notice the difference between the following two diagrams:

    \xymatrix{ \bullet \ar[r] \ar@{.>}[r] & \bullet }

Latex example xypics standard arrow.png

        \bullet \ar@/^/[r]
        \ar@/_/@{.>}[r] &
        \bullet }

Latex example xypics curved arrow.png

The modifiers between the slashes define how the curves are drawn. Xy-pic offers many ways to influence the drawing of curves; for more information, check the Xy-pic documentation.

If you are interested in a more thorough introduction then consult the Xy-pic Home Page, which contains links to several other tutorials as well as the reference documentation.

Previous: PSTricks Index Next: Creating 3D graphics