# How to color just the \vec symbol?

How do I color only the vector symbol in \vec f? I'm using beamer, so xcolor is already loaded.

Extra "points" to an answer that also explains how to fish..and not only gives me the fish.

Thanks!

-

$\color{red}{\vec{\color{black}{f}}}$


and if you want it a bit more automated

\newcommand{\colorvec}[1]{{\color{red}\vec{\color{black}{#1}}}}


which is to be used as $\colorvec{g}$

-
What about $\colorvec{a}+\colorvec{b}$? –  egreg Mar 4 '12 at 0:11
At least correct it. –  egreg Mar 4 '12 at 0:17
@egreg done, by adding extra grouping {} –  cmhughes Mar 4 '12 at 0:24

You can use \textcolor that works also in math mode:

\documentclass{article}
\usepackage{xcolor}
\newcommand{\rvec}[2][black]{%
\textcolor{red}{\vec{\textcolor{#1}{#2}}}
}
\begin{document}
$\vec{x}$

$\rvec{x}$

$\rvec[green]{x}$
\end{document}


In this way you're sure that the color change will be limited to this object. I've added an optional argument to change also the color of the variable.

-
Great idea! love it! I'm surprised it didn't come up in other questions of this type. –  Yossi Farjoun Mar 4 '12 at 0:12
@YossiFarjoun Probably because it's a bad idea to color the arrow. ;-) –  egreg Mar 4 '12 at 0:28
I meant, for example here. I think that for a presentation, color is great when used sparingly...in this case, I want to have the arrow overlaid...so I want it in a different color to bring the attention to it... –  Yossi Farjoun Mar 4 '12 at 14:53