9

Is there a way to color certain (but not all) arrows using \xymatrix? I wish the following ignorant attempt would work!!

\usepackage{xypic,color}
\begin{document}
\[
\xymatrix
{
X\ar[r]\color{red}{\ar[d]} & Y\\
Z
}
\]
\end{document}
Kristen
  • 5,003

1 Answers1

11

Specify the color option to the xy package. Then you could apply a color style by @[color].

For example:

\documentclass{article}
\usepackage{color}
\usepackage[color,matrix,arrow]{xy}
\begin{document}
\[
\xymatrix
{
X\ar[r] \ar@[red][d] & Y\\   Z
}
\]
\end{document}

alt text

Note: load xy, not xypic which produces at least a warning. To be able to provide options specifically for each package, write one \usepackage for each package. Perhaps use the enhanced package xcolor instead of color.

CarLaTeX
  • 62,716
Stefan Kottwitz
  • 231,401
  • The output isn't yielding color at all. (My preliminary glance was mistaken, apparently.) I'm working within the a0poster class, but I've tried to run this as an article with the same results. – Kristen Dec 13 '10 at 21:02
  • @Kristen: Do you mean you did not get color with my example or with your code? – Stefan Kottwitz Dec 13 '10 at 21:05
  • I'm not getting color with your code. – Kristen Dec 13 '10 at 21:29
  • Hm, I did ... I used pdfTeX. And you? Specifying the driver could help. In the case of pdfTeX: \usepackage[color,matrix,arrow,pdf]{xy}. And, especially if xy complains about an unknown option: update xy-pic to 3.8 or above. I'm using xy 3.8.4. – Stefan Kottwitz Dec 13 '10 at 21:33
  • I'm also using pdfTeX. I think the problem might be with my version of xy-pic; mine is only 3.7. I also just noticed a warning: shape [red] not defined. Is the older version of xy-pic reading the argument as a shape parameter? – Kristen Dec 13 '10 at 21:41
  • I tried it, and it works fine with pdflatex. (It does not work with latex + dvips, but you shouldn't be using them anyway unless you have a very good reason...) – Jukka Suomela Dec 13 '10 at 22:06
  • I can confirm that it does not work in TeX Live 2009 (as shipped with Ubuntu 10.10). – Caramdir Dec 13 '10 at 22:26
  • @Caramdir: did you test it with the current xy 3.8.4? Afaik versions older than 3.8 don't support pdfTeX, though choosing a suitable driver together with the color option might work. – Stefan Kottwitz Dec 13 '10 at 22:36
  • No, I tested with the version included in Ubuntu (3.7). Compiling with pdflatex works, apart from the color. Compiling via latex and dvips gives the color (when specifying the dvips driver). So there are two options: update xy or compile the old-fashioned way. – Caramdir Dec 13 '10 at 22:43
  • Is there a way to adjust this so that it works with dvips? The color shows up fine for me when compiling with pdfTeXify, but elsewhere in my document I have some images created using pstricks (and pdftricks), so I need to do div-->ps-->pdf and the color doesn't display when I do that. –  Jan 16 '12 at 16:30
  • @潘傑森: I converted your post to a comment now, because answer posts are only for solutions to the original question here. Feel free to ask a follow-up question using the "Ask Question" button above. Please link to this question then. – Martin Scharrer Jan 16 '12 at 18:00
  • @CarLatex Hi! I am trying to use this and create dashed arrows at the same time. So my code would be

    \xymatrix{A\ar@{-->}[r]&B}

    but I want a red arrow. Now, if I type

    \xymatrix{&A\ar@{-->}[red][r]&B}

    no arrow appears. If I type

    \xymatrix{&A\ar@[red]{-->}[r]&B} the arrow is not red and changes directions. How can I solve this?

    – Ana Aug 05 '21 at 05:25
  • 1
    @Ana I got the message and can take a look, but earliest in 8 hours (traveling). If you like, you can post it as a separate question, otherwise I'll be here again later today. – Stefan Kottwitz Aug 05 '21 at 08:11
  • Thank you both.@CarLatex, I could only pin someone else besides the author, that's why I included you, as you editted the text by Stefan? @Stefan, 8h is perfect, no rush! Thanks! – Ana Aug 05 '21 at 08:53
  • @Ana My edit was non relevant, you're welcome! – CarLaTeX Aug 06 '21 at 11:52
  • @StefanKottwitz: Stefan, I figured it out: just add @ before every argument. Sorry for the basic question! – Ana Aug 06 '21 at 13:36
  • @CarLaTeX Ok. Noted! ;) – Ana Aug 06 '21 at 13:36