# XeLaTeX problem with a vector arrow

I am trying to write $\overrightarrow{V}_{AB}$ with the vector over only V, but when I do this then the subscript AB goes far from V. On the other hand when I use the vector over the V and AB it seems wrong and not so beautiful. What am I doing wrong? Thank you very much!

• Any reason against $\vec{V}_{AB}$? – Thorsten Donig Feb 20 '14 at 17:54
• I didn't know that command! Thank you! – Adam Feb 20 '14 at 17:57
• Then you should read some introductory material like the Dickimaw LaTeX Books. – Thorsten Donig Feb 20 '14 at 17:59
• I will consider them. – Adam Feb 20 '14 at 18:01

If you use unicode-math along with XeLaTeX, there's no difference in what's printed with or without the arrow over the V; only the arrow length changes if you use \vec or \overrightarrow:

\documentclass{article}
\usepackage{unicode-math}

\linespread{1.05} % if you have arrows over capital letters

\begin{document}
$V_{AB}$ \sbox0{$V_{AB}$}\the\wd0

$\vec{V}_{AB}$ \sbox0{$\vec{V}_{AB}$}\the\wd0

$\overrightarrow{V}_{AB}$ \sbox0{$\overrightarrow{V}_{AB}$}\the\wd0
\end{document}


The \sbox commands are just to print the width of the material, showing that the widths are the same.

Of course, the letter shapes in this case leave a hole, which should be corrected visually. It's a case similar to $\sqrt{\log x}$, where adding a thin space is better

$\sqrt{\,\log x}$


or $x^2/2$ where a negative thin space is recommended

$x^2\!/2$


Here's the realizations, left without the correction, right with the correction:

So, in your case, I'd suggest

\documentclass{article}
\usepackage{unicode-math}

\linespread{1.05} % if you have arrows over capital letters

\begin{document}
$V_{\!AB}$

$\vec{V}_{\!AB}$

$\overrightarrow{V}_{\!AB}$

\end{document}


I would definitely not recommend using \overrightarrow without unicode-math, as the result is appalling awful

and I'm not referring to the space between the variable and the subscript, but to the size of the arrow, which is too large.

Welcome to TeX.se! :-)

Try this: $\overrightarrow{V}_{\!AB}$.

The \! inserts negative horizontal spacing.

• I tried it and it didn't work. Thanks for the answer though. – Adam Feb 20 '14 at 17:39
• @Adam: How strange; it should. Try multiple \! in a row, e.g. $\overrightarrow{V}_{\!\!\!\!AB}$ just to see if it makes a difference. If not, please put your full LaTeX code in your original question. – mhelvens Feb 20 '14 at 17:43
• That worked!Why there was that problem though? Shouldn't without these corrections work the first time? – Adam Feb 20 '14 at 17:45
• \overrightarrow creates a \vbox: a rectangle which, by default, does not overlap with other boxes. Such boxes can have visible content anywhere inside (or even outside) their bounds, so making them overlap will often be the wrong thing to do. Unfortunately, (La)TeX cannot take every possible situation into account. That's why there are ways to make manual corrections. – mhelvens Feb 20 '14 at 17:51

The problem is that \overrightarrow produces a box. When a subscript is added to a box, it treats it as a rectangle, and can't see what's inside. When a subscript is added to a character, it sees the italic correction of that character (roughly proportional to the amount of slant) and compensates for it. The easy work-around is to insert negative space, with the amount based on trial and error. The difficult way is to try to measure the necessary amount of negative space automatically:

\documentclass{article}
\usepackage{amsmath}
\makeatletter
\def\overrightarrowwithsubscript#1{\mathpalette{\@oraws{#1}}}
\def\@oraws#1#2#3{%
\begingroup
\setbox0=\hbox{$#2{{#1}_{#3}}$}%
\setbox2=\hbox{$#2{\overrightarrow{#1}_{#3}}$}%
\overrightarrow{#1}_{\hskip-\@tempdima #3}
\endgroup}
\begin{document}
$\overrightarrow{V}_{AB} \qquad \overrightarrowwithsubscript{V}{AB}$

\bigskip
$\frac{\overrightarrow{V}_{AB}}{\overrightarrow{V}_{AB}}\qquad \frac{\overrightarrowwithsubscript{V}{AB}}{\overrightarrowwithsubscript{V}{AB}}$
\end{document}


You can use the esvect package: it manages the subscript with a \vv*command, the arrow doesn't collide with what is underneath and you can choose between eight forms of arrow. Here is an example, to be compared with \overrightarrow:

\documentclass[12pt, a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage[f]{esvect}

\begin{document}

$\vv*{V}{AB}\qquad\vv*{V}{\!AB}\qquad \overrightarrow{V}_{AB}$

\end{document}