The \vec
command uses \mathchar"017E
as the arrow, while \overrightarrow
uses \mathchar"3221
. Both look like scaled versions of each other to me. So we can replicate \overrightarrow
with the arrow tip of \vec
. I propose two versions, a LaTeX one, and one following the amsmath
route. For the amsmath
version I give another variant that scales the minus horizontally to make it thinner.
\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{kpfonts}
\newcommand*{\vv}[1]{\vec{\mkern0mu#1}}
\makeatletter
\newcommand{\vect}[1]{%
\vbox{\m@th \ialign {##\crcr
\vectfill\crcr\noalign{\kern-\p@ \nointerlineskip}
$\hfil\displaystyle{#1}\hfil$\crcr}}}
\def\vectfill{%
$\m@th\smash-\mkern-7mu%
\cleaders\hbox{$\mkern-2mu\smash-\mkern-2mu$}\hfill
\mkern-7mu\raisebox{-3.81pt}[\p@][\p@]{$\mathord\mathchar"017E$}$}
\newcommand{\amsvect}{%
\mathpalette {\overarrow@\vectfill@}}
\def\vectfill@{\arrowfill@\relbar\relbar{\raisebox{-3.81pt}[\p@][\p@]{$\mathord\mathchar"017E$}}}
\newcommand{\amsvectb}{%
\mathpalette {\overarrow@\vectfillb@}}
\newcommand{\vecbar}{%
\scalebox{0.8}{$\relbar$}}
\def\vectfillb@{\arrowfill@\vecbar\vecbar{\raisebox{-4.35pt}[\p@][\p@]{$\mathord\mathchar"017E$}}}
\makeatother
\begin{document}
\begin{align}
\mathchar"017E, \mathchar"3221\\
\vec u,\ \vv u,\ \vv{OA},\ \vv{BC},\ \overrightarrow{AB} \\
\vect{u}, \vect{OA}, \vect{BC}, \vect{AB}\\
\amsvect{u}, \amsvect{OA}, \amsvect{BC}, \amsvect{AB}\\
\amsvectb{u}, \amsvectb{OA}, \amsvectb{BC}, \amsvectb{AB}
\end{align}
\end{document}
Note that this kind of building extensible accents with minus signs and short arrows shows the typical LaTeX weakness that those accents render oddly on certain resolutions. The raise parameter -3.81pt
is the best approximation I found to mitigate this problem. You might want to fiddle with it to get better results. Also, the third variant with scaled minus has yet another parameter (the 0.8
scaling factor) that probably needs fine-tuning.
The vertical space between the arrows and the letters is governed by the use of \overarrow@
from amsmath
, so the space you get is the same as for \overrightarrow
. If we want it a little lower, we make a new version of \overarrow@
and use that in \amsvect
and \amsvectb
:
\makeatletter
\def\my@overarrow@#1#2#3{\vbox{\ialign{##\crcr #1#2\crcr \noalign{\kern-\p@\nointerlineskip}$\m@th \hfil #2#3\hfil $\crcr}}}
\newcommand{\amsvect}{%
\mathpalette {\my@overarrow@\vectfill@}}
\def\vectfill@{\arrowfill@\relbar\relbar{\raisebox{-3.81pt}[\p@][\p@]{$\mathord\mathchar"017E$}}}
\newcommand{\amsvectb}{%
\mathpalette {\my@overarrow@\vectfillb@}}
\newcommand{\vecbar}{%
\scalebox{0.8}{$\relbar$}}
\def\vectfillb@{\arrowfill@\vecbar\vecbar{\raisebox{-4.35pt}[\p@][\p@]{$\mathord\mathchar"017E$}}}
\makeatother
The magic number here is the \kern-\p@
in \my@overarrow
, which pushes the arrow one point deeper. Again, this is open for fine tuning. Note that this is the same value that is already used in \vect
.
\overrightarrow
with a smaller arrow tip?\vec
arrow tip.