10

I want to have a double headed vector. I tried \overleftright, but the appearance is all but pretty. I would like to get the same kind of symbol, but with \vec appearance. Is it possible?

1
  • 1
    \overrightarrow. \overleftarrow. <-- mentioned to improve search results...
    – kando
    Oct 20, 2017 at 18:35

1 Answer 1

13

Built using stacks:

\documentclass{article}
\def\vecsign{\mathchar"017E}
\def\dvecsign{\smash{\stackon[-1.95pt]{\vecsign}{\rotatebox{180}{$\vecsign$}}}}
\def\dvec#1{\def\useanchorwidth{T}\stackon[-4.2pt]{#1}{\,\dvecsign}}
\usepackage{stackengine}
\stackMath
\usepackage{graphicx}
\begin{document}
$ \vec c \vec A  \dvec c \dvec A$
\end{document}

enter image description here

There remains a slight possibility for overlap, when, for example, having $\dvec d \dvec b$. That issue can be remedied by using a little kern to make a narrower \dvec, as follows. To recover the original, reset \shrinkage to 0mu.

\documentclass{article}
\def\shrinkage{2.1mu}
\def\vecsign{\mathchar"017E}
\def\dvecsign{\smash{\stackon[-1.95pt]{\mkern-\shrinkage\vecsign}{\rotatebox{180}{$\mkern-\shrinkage\vecsign$}}}}
\def\dvec#1{\def\useanchorwidth{T}\stackon[-4.2pt]{#1}{\,\dvecsign}}
\usepackage{stackengine}
\stackMath
\usepackage{graphicx}
\begin{document}
$ \vec c \vec A  \dvec c \dvec A$
$\dvec d \dvec b $
\end{document}

enter image description here

6
  • 2
    Because of my font election, I had to change -1.95 for -2.60, but your answer is abusuletly brilliant and elegant. Feb 25, 2014 at 18:29
  • @AlfredoHernández Note that I added a \smash to \dvecsign else it had too much dead space above it. Feb 25, 2014 at 18:30
  • Just wondering, is this possible to accomplish via \newcommand instead of \def? Feb 26, 2014 at 21:01
  • 1
    Yes. For \shrinkage, \vecsign and \dvecsign, merely substituting \newcommand for \def will suffice. For the case of \dvec, substitute \newcommand\dvec[1] for \def\dvec#1. The differences between \def and \newcommand, outside of the syntax, is that \newcommand arguments can have \pars in them, whereas \def cannot, unless you define it \long. Also, \newcommand will only proceed, if the command name does not already exist, whereas \def will overwrite an existing macro. And, of course, \newcommand can take optional arguments conveniently. Feb 26, 2014 at 21:06
  • Yeah, that's why I usually use \newcommand (just simple things, though). That worked nicely. Feb 26, 2014 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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