4

How do I rotate the label on a arrow in xymatrix? Say, I want the label texts parallel with the arrow?

\documentclass[12pt, a4paper]{article}% a minimal example

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[all]{xy}
\xyoption{pdf}
\begin{document}
  \[
  \xymatrix{
    x\ar[d]^{looooooong}\\
    y
    }
  \]
\end{document}
ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
Ma Ming
  • 2,306

3 Answers3

4

Perhaps xy has it's own rotation support, but I think not, but you can use standard LaTeX rotations:

enter image description here

\documentclass[12pt, a4paper]{article}% a minimal example

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern,graphicx}
\usepackage[all]{xy}
\xyoption{pdf}
\begin{document}
  \[
  \xymatrix{
    x\ar[d]^{\rotatebox{90}{$\scriptstyle looooooong$}}\\
    y
    }
  \]
\end{document}
David Carlisle
  • 757,742
4

You can add \xyoption{rotate}. The explanation for rotation of labels or any object appears in the page 29 in XY-pic reference manual.

\documentclass[12pt, a4paper]{article}% a minimal example
\usepackage[all]{xy}
\xyoption{rotate}
\xyoption{pdf}
\begin{document}
  \[
  \xymatrix{
    x\ar[d]^[@!-90]{\scriptstyle looooooong}\\
    y
    }
  \]
\end{document}

or

\documentclass[12pt, a4paper]{article}% a minimal example
\usepackage[all]{xy}
\xyoption{rotate}
\xyoption{pdf}
\begin{document}
  \[
  \xymatrix{
    x\ar[d]^[right]{\scriptstyle looooooong}\\
    y
    }
  \]
\end{document}
Torbjørn T.
  • 206,688
Quique Ruiz
  • 205
  • 1
  • 5
  • Welcome to TeX.SX! If you select text and click the button marked {} (or use Ctrl+K) the text will be highlighted as code. Then there's no need for the <br>s. – Torbjørn T. Jun 09 '14 at 22:28
1

If you are willing to use tikz-cd instead of xy, you could just rotate the label like you would do for any TikZ-node.

% arara: pdflatex

\documentclass{article}
\usepackage{tikz-cd}
\usepackage{mathtools} % for the \text{} command
\begin{document}
\[
\begin{tikzcd}
x  \ar{d}[%
    ,rotate=+90 % counter clockwise rotation
    ,below % attach label to the right of the arrow
    ,yshift=-0.3ex % optional for movement to the right. 
    ]{\text{looooooong}}\\
y
\end{tikzcd}
\]
\end{document}

enter image description here

Update

In comment you asked for an automatic solution for rotated labels. Done in tikz-cd, this could look like this:

% arara: pdflatex

\documentclass{article}
\usepackage{tikz-cd}
\tikzset{mystyle/.style={sloped, anchor=south}}
\usepackage{mathtools} % for the \text{} command

\begin{document}
\[
\begin{tikzcd}[every label/.append style={mystyle}]
\bullet & \bullet & \bullet\\
\bullet & x  \ar{ul}{xy} \ar{u}{xy} \ar{ur}{xy} \ar{l}{xy} \ar{r}{xy} \ar{dl}{xy} \ar{d}{\text{looooooong}} \ar{dr}{xy} & \bullet\\
\bullet & y & \bullet
\end{tikzcd}
\]
\end{document}

enter image description here

In my opinion, each label should be readable from the right or from below. So instead of using every label/.append style={mystyle} for the whole image, I would write \ar{ul}[mystyle]{xy} for any arrow and use my first solution for the down-arrow-case.

LaRiFaRi
  • 43,807