Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
1  
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 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 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 at 14:41
    
@user87690 Yes, you're right. It seems that *+\txt{} is the way it is supposed to be. –  karlkoeller Mar 1 at 15:42
add comment

2 Answers 2

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

As a workaround, add the following lines in your preamble

\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:

enter image description here

share|improve this answer
add comment

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}

enter image description here

It is also possible to overwrite the existing \txt:

\renewcommand\txt[2][t]{...}
share|improve this answer
    
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 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 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 at 10:27
    
ok, see my next edit –  Herbert Mar 1 at 10:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.