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?
Asked
Active
Viewed 8,463 times
10
1 Answers
14
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}

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}

Steven B. Segletes
- 237,551
-
2Because of my font election, I had to change -1.95 for -2.60, but your answer is abusuletly brilliant and elegant. – Alfredo Hernández Feb 25 '14 at 18:29
-
@AlfredoHernández Note that I added a
\smashto\dvecsignelse it had too much dead space above it. – Steven B. Segletes Feb 25 '14 at 18:30 -
Just wondering, is this possible to accomplish via
\newcommandinstead of\def? – Alfredo Hernández Feb 26 '14 at 21:01 -
1Yes. For
\shrinkage,\vecsignand\dvecsign, merely substituting\newcommandfor\defwill suffice. For the case of\dvec, substitute\newcommand\dvec[1]for\def\dvec#1. The differences between\defand\newcommand, outside of the syntax, is that\newcommandarguments can have\pars in them, whereas\defcannot, unless you define it\long. Also,\newcommandwill only proceed, if the command name does not already exist, whereas\defwill overwrite an existing macro. And, of course,\newcommandcan take optional arguments conveniently. – Steven B. Segletes Feb 26 '14 at 21:06 -
Yeah, that's why I usually use
\newcommand(just simple things, though). That worked nicely. – Alfredo Hernández Feb 26 '14 at 21:19 -
Like @AlfredoHernández I had to change the
\stackon[-1.95]to\stackon[-2.35pt]to have the arrows overlap, apart from that nice solution! (would be nice to have an explanation on which numbers do what) – BadAtLaTeX Nov 11 '17 at 15:50
\overrightarrow.\overleftarrow. <-- mentioned to improve search results... – kando Oct 20 '17 at 18:35