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?

Torbjørn T.
  • 206,688
user74973
  • 4,071
  • 2
    \overleftrightarrow{} from amsmath package. – Sigur Jul 07 '15 at 15:56
  • 1
    \overleftrightarrow{AB}, more precisely. – GuM Jul 07 '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 09 '15 at 21:10
  • 1
    @Gustavo Mezzetti Does \overrightarrow{} give me the symbol for a ray? – user74973 Jul 09 '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 09 '15 at 23:20
  • @Gustavo Mezzetti I also had asked "How do I draw an arrow above a pair of letters to indicate a ray?" – user74973 Jul 10 '15 at 12:44

1 Answers1

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

  • In my opinion, the small arrow head is much much better than the default one. Very nice! – Sigur Jul 07 '15 at 18:58
  • @Steven B. Segletes I agree with Sigur - the arrowheads on the default arrows are too big. I plan to put arrows, with arrowheads at both ends to indicate a line, and with arrowheads at the right end to indicate a ray. I don't know anything about your code in the preamble. Please give me the code that I need to put in the preamble for lines and rays. (I will put arrows only above a pair of letters.) – user74973 Jul 09 '15 at 21:21
  • @user74973 I have provided an addendum with \ray. As far as the preamble, I have provided everything you need. The \ray does have a square left end, rather than rounded. If this is an issue, let me know. – Steven B. Segletes Jul 10 '15 at 01:41
  • @Steven B. Segletes Thanks for including the code for typesetting rays. Looks nice! – user74973 Jul 10 '15 at 13:17
  • @Steven B. Segletes I am (almost) sure that I will be typesetting arrows, with arrowheads at both ends of a line segment or only at the right end of a line segment, over a pair of capital letters. Please tell me which commands that you have in your preamble are pertinent to what I need. – user74973 Jul 10 '15 at 13:17
  • 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
  • @Steven B. Segletes I am using the font included with amsart. – user74973 Jul 10 '15 at 13:42
  • 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 smashin 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" (https://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 09:48
  • @LeonMeier That problem is not wholly unexpected. It is neither a hinting issue nor a rendering issue. It arises from the fact that a \Huge letter is not merely a scaled up version of the normal-sized letter, just as a \tiny letter is not merely a scaled down version of the normal-sized letter. What this means is that the relative proportions of the letters have changed, and so the amount of adjustment that is needed for my custom-fitted algorithms needs to change (basically for each font-size and certainly so if the actual font is changed). This is the essential drawback of my approach – Steven B. Segletes Oct 11 '16 at 11:41