# Why is \txt element of \xymatrix moved downwards?

I wonder why is the textual "A" in \xymatrix{A \ar[r] & \txt{A}} moved downwards. All I want is to have textual elements in xymatrix with possibility of line breaks inside the element. I thought \txt is for this but the positioning seems weird to me.

EDIT: Thank you for answers. I have found following solution: Just put there *\txt{} instead of \txt{}. Actually then there is no spacing around the text, so *+\txt{} looks better. I just wonder if this is standard way to do it. It seems to me that there should be a standard way to do it, since it looks like standard demand to have textual multiline entries, but both your answers look like workarounds.

-
The positioning of \txt with one line argument is mysterious; with two or more lines it's basically vertically centered with respect to the arrow stem. – egreg Mar 1 '14 at 10:30
I had already discovered *+\txt{}, but the baseline is still weird. I've used \xymatrixoften in the past, but \txt only for placing text over arrows. Probably it is not meant to be used in the way you do. – karlkoeller Mar 1 '14 at 11:23
@karlkoeller: The documentation says otherwise. See section 3 in home.ustc.edu.cn/~xwchen/Useful%20files/xyguide.pdf . It says it is meant to be used like this. – user87690 Mar 1 '14 at 14:41
@user87690 Yes, you're right. It seems that *+\txt{} is the way it is supposed to be. – karlkoeller Mar 1 '14 at 15:42

The positioning of text inside \txt is really strange...

\makeatletter
\xydef@\txt@ii#1{\vbox{\vspace*{-7pt}%
\let\\=\cr
\tabskip=\z@skip \halign{\relax\hfil\txtline@@{##}\hfil\cr\leavevmode#1\crcr}}}
\makeatother


MWE:

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

\makeatletter
\xydef@\txt@ii#1{\vbox{\vspace*{-7pt}%
\let\\=\cr
\tabskip=\z@skip \halign{\relax\hfil\txtline@@{##}\hfil\cr\leavevmode#1\crcr}}}
\makeatother

\begin{document}

\xymatrix{A \ar[r] & \txt{A}}

\bigskip

\xymatrix{A \ar[r] & \txt{A\\B}}

\bigskip

\xymatrix{A \ar[r] & \txt{A\\B\\C}}

\end{document}


Output:

-

it is set in mathmode by default and \txt uses the text mode. If you want an upright A use:

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

\begin{document}
\xymatrix{A \ar[r] & \mathrm{A}}

\end{document}


if you want real text, then use

\documentclass{article}
\usepackage[all]{xy}
\newcommand\TXT[2][t]{\tabular[#1]{l}#2\endtabular}

\begin{document}
\xymatrix{A \ar[r] & \TXT{name of \\ class of spaces}}

\xymatrix{A \ar[r] & \TXT[b]{name of \\ class of spaces}}

\xymatrix{A \ar[r] & \TXT[c]{name of \\ class of spaces}}
\end{document}


It is also possible to overwrite the existing \txt:

\renewcommand\txt[2][t]{...}

-
But I don't want mathematical upright A, I really want to put text there like \txt{name of class of spaces} or \txt{name of // class of spaces}. I was just wondering why it moves downwards. – user87690 Mar 1 '14 at 10:16
I don't know what \txt really does without looking into the code of xy. However, use \textrm{...} instead. See edited answer. – Herbert Mar 1 '14 at 10:20
Sorry, I really meant \txt{name of \\ class of spaces} as an example when I want a line break in the text element. – user87690 Mar 1 '14 at 10:27
ok, see my next edit – Herbert Mar 1 '14 at 10:33