2

How do I typeset a line segment, with arrowheads at each end, above a pair of letters to indicate a line? I know that $\overline{AB}$ can be used to typeset a line segment between points A and B. How do I draw an arrow above a pair of letters to indicate a ray?

  • 2
    \overleftrightarrow{} from amsmath package. – Sigur Jul 7 '15 at 15:56
  • 1
    \overleftrightarrow{AB}, more precisely. – GuM Jul 7 '15 at 16:07
  • @Sigur and Gustavo Mezzetti Thanks for the command. I am looking to put an arrow above two letters. This will be just fine. – user74973 Jul 9 '15 at 21:10
  • 1
    @Gustavo Mezzetti Does \overrightarrow{} give me the symbol for a ray? – user74973 Jul 9 '15 at 21:13
  • 1
    Of course, \overrightarrow{AB} typesets “AB” with an arrow pointing rightward above the two letters; but you asked for a segment “with arrowheads at each end“, didn’t you? :-) – GuM Jul 9 '15 at 23:20
4

The comments have already mentioned \overleftrightarrow. Here is an alternative that tries to make the segment use the same heads as \vec, also shown for comparison.

Based on my answer at "Double headed" vector, except that I had to make it extensible to match segments of different sizes.

On the left are two \vecs, two \dvecs and on the right are two \overleftrightarrows. Below is a very wide \dvec.

EDITED, based on Leon's suggestion, to improve the height of the \dvec, so as to be compatible with \vec when using \left...\right syntax.

\documentclass{article}
\usepackage{scalerel}
\def\shrinkage{-2.4mu}
\def\vecsign#1{\rule[1.388\LMex]{\dimexpr#1-2.5pt}{.36\LMpt}%
  \kern-6.0\LMpt\mathchar"017E}
\def\dvecsign#1{\rule{0pt}{7\LMpt}\smash{\stackon[-1.989\LMpt]{%
  \SavedStyle\mkern-\shrinkage\vecsign{#1}}%
  {\rotatebox{180}{$\SavedStyle\mkern-\shrinkage\vecsign{#1}$}}}}
\def\dvec#1{\ThisStyle{\setbox0=\hbox{$\SavedStyle#1$}%
  \def\useanchorwidth{T}\stackon[-4.2\LMpt]{\SavedStyle#1}{\,\dvecsign{\wd0}}}}
\usepackage{stackengine,amsmath}
\stackMath
\usepackage{graphicx}
\begin{document}
$ \vec c ~\vec A  ~\dvec{ac} ~\dvec{AB} ~\textrm{vs.}
  ~\overleftrightarrow{ac} ~\overleftrightarrow{AB}$

$\dvec{ABCD} ~\scriptstyle \dvec A ~\dvec{AB}~\scriptscriptstyle \dvec A ~\dvec{AB}$

$
\left(\dvec{A}\right)\left(\vec{A}\right)
\scriptstyle\left(\dvec{A}\right)\left(\vec{A}\right)
\scriptscriptstyle\left(\dvec{A}\right)\left(\vec{A}\right)
$
\end{document}

enter image description here

ADDENDUM

Based on the OP's request, I provide \ray{} below:

\documentclass{article}
\usepackage{scalerel}
\def\shrinkage{-2.4mu}
\def\vecsign#1{\rule[1.388\LMex]{\dimexpr#1-2.5pt}{.36\LMpt}%
  \kern-6.0\LMpt\mathchar"017E}
\def\dvecsign#1{\rule{0pt}{7\LMpt}\smash{\stackon[-1.989\LMpt]{\SavedStyle\mkern-\shrinkage\vecsign{#1}}%
  {\rotatebox{180}{$\SavedStyle\mkern-\shrinkage\vecsign{#1}$}}}}
\def\dvec#1{\ThisStyle{\setbox0=\hbox{$\SavedStyle#1$}%
  \def\useanchorwidth{T}\stackon[-4.2\LMpt]{\SavedStyle#1}{\,\dvecsign{\wd0}}}}
\def\theraysign#1{\rule{0pt}{17\LMpt}\rule[1.384\LMex]{\dimexpr#1-2.5pt}{.40\LMpt}%
  \kern-6.0\LMpt\mathchar"017E}
\def\raysign#1{\rule{0pt}{7\LMpt}\smash{%
  \SavedStyle\mkern-\shrinkage\theraysign{#1}}}
\def\ray#1{\ThisStyle{\setbox0=\hbox{$\SavedStyle#1$}%
  \def\useanchorwidth{T}\stackon[-4.2\LMpt]{\SavedStyle#1}{\,\raysign{\wd0}}}}
\usepackage{stackengine,amsmath}
\stackMath
\usepackage{graphicx}
\begin{document}
$ \vec c ~\vec A  ~\ray{ac} ~\ray{AB} ~\textrm{vs.}
  ~\overleftrightarrow{ac} ~\overleftrightarrow{AB}$

$\ray{ABCD} ~\scriptstyle \ray A ~\ray{AB}~\scriptscriptstyle \ray A ~\ray{AB}$

$
\left(\ray{AB}\right)\left(\vec{AB}\right)
\scriptstyle\left(\ray{AB}\right)\left(\vec{AB}\right)
\scriptscriptstyle\left(\ray{AB}\right)\left(\vec{AB}\right)
$
\end{document}

enter image description here

| improve this answer | |
  • In my opinion, the small arrow head is much much better than the default one. Very nice! – Sigur Jul 7 '15 at 18:58
  • 1
    @user74973 In the ADDENDUM code, everything between \usepackage{scalerel} and \usepackage{graphicx} (including those lines) should be copied into your preamble, which will allow the use of \dvec and \ray. Note that the measurements and alignment are calibrated for the Computer-Modern font, and will need tweaking if you wish to employ this approach for other fonts. – Steven B. Segletes Jul 10 '15 at 13:23
  • 1
    @user74973 The code using amsartworks just fine, I just verified, unless you employ additional font modifications after using amsart. For example, \usepackage{txfonts} will require a rework, for example. – Steven B. Segletes Jul 10 '15 at 13:47
  • 1
    @LeonMeier To fix the \left issue (I think), one can add a \rule{0pt}{7pt} just prior to the smash` in the definition of \dvecsign. As to the nitpick. Any overlaid glyph arrangement will be subject to the vagaries of the rendering software at lower resolutions, because of the feature called "hinting" (en.wikipedia.org/wiki/Font_hinting) – Steven B. Segletes Oct 10 '16 at 15:35
  • 1
    @LeonMeier You are right. Thanks for the edit. – Steven B. Segletes Oct 11 '16 at 9:48

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