0

I want to put arrows on top of various pieces of several formulas but I want the arrows to be of the same size and height. What is a good solution? For example consider

\overleftarrow{x} \quad \overleftarrow{x^2} \quad \overrightarrow{3xy}

the arrows will naturally be at different heights and of different lengths due to the varying sizes of the individual formula boxes. I want to force them to be more even.

Edit 1:

The promising suggestion was to use phantom to even out the height of arrows.

For now I decided to put the formulas into a tabular and allocate a row for the arrows and adjust the spacing between the rows.

Edit 2: Here is a MWE without phantom or separate rows for the arrows, etc.

 \documentclass{article}
 \usepackage{mathtools}
 \def \ra {\overrightarrow}
 \def \la {\overleftarrow}
 \begin{document}    
 \begin{tabular}{cccc}
  $\ra A$& $\la{ E^2}$ &$\la {5FG^3}$& $\ra{ H^2 I^3}$\\ 
  $\ra {BA^5} $& $\ra {AE^2}$ &$\ra {G}$& $\ra {12 H^2 I^3}$\\ 
 \end{tabular}
 \end{document}
  • 1
    Please make a MWE – egreg Nov 21 '14 at 16:27
  • 1
    Use a \vphantom of the tallest element; that is \vphantom{x^2} in this case, and insert it in the other not-as-tall elements: \overleftarrow{\vphantom{x^2}x} – Werner Nov 21 '14 at 16:28
  • 1
    On the other hand, an arrow hanging from nowhere doesn't seem the best. – egreg Nov 21 '14 at 16:30
  • So you have several pieces of a formula on which to put an arrow. For the "the same heigh" part, if you want them at the same height, @Werner's comment will help. If you want them of the same height, well, I don't get that. With "of" it sounds more like the arrows for some reason are of different thicknesses. This is more of a vocabulary note, but mind your preposotions :), because I guess they don't turn out to have different thicknesses. As for the size and length, well, for the size again I don't get the problem, for the lengths you can try fiddling with \hspaces or \phantoms. – MickG Nov 21 '14 at 16:41
  • 1
    @Maesumi: Yes, one would probably use \mathclap{<stuff>}\hphantom{<long entry>} (using mathtools). – Werner Nov 25 '14 at 22:47
1

You can get the arrows to be at the same vertical height it you apply a \vphantom{<text>} with <text> being the tallest content, and if you want them to be the same width you can typeset the content into a fixed width \makebox. In this case x^2 is the tallest content, so we get:

enter image description here


In the above, I fixed the width of the \makebox to be 2.0em. If you have much wider content you can either adjust this width manually, or set it to be equal to the widest content that you have. So, in the second example I assumes that ABCD is your widest element so now the width of the arrow is just enough to cover ABCD:

enter image description here

This can also be done using \mathmakebox.


Code: Fixed Width:

 \documentclass{article}
 \usepackage{mathtools}

 \newcommand*{\TallestContent}{$x^2$}% <-- This should be the tallest content

 \newcommand*{\ra}[1]{\overrightarrow{\makebox[2.0em]{$#1$\vphantom{\TallestContent}}}}
 \newcommand*{\la}[1]{\overleftarrow{\makebox[2.0em]{$#1$\vphantom{\TallestContent}}}}

 \begin{document}    
     $\la{x} \quad \la{x^2} \quad \ra{3xy}$
 \end{document}

Code: Measured Width using \makebox:

 \documentclass{article}
 \usepackage{mathtools}

  \newcommand*{\WidestContent}{$ABCD$}% <-- This should be the widest content
  \newcommand*{\TallestContent}{$x^2$}% <-- This should be the tallest content

  \newlength{\MyWidth}
  \settowidth{\MyWidth}{\WidestContent}% 

 \newcommand*{\ra}[1]{\overrightarrow{\makebox[\MyWidth]{$#1$\vphantom{\TallestContent}}}}
 \newcommand*{\la}[1]{\overleftarrow{\makebox[\MyWidth]{$#1$\vphantom{\TallestContent}}}}

 \begin{document}    
     $\la{x} \quad \la{x^2} \quad \ra{3xy} \quad \ra{ABCD}$
 \end{document}

Code: Measured Width using \mathmakebox:

  \documentclass{article}
  \usepackage{mathtools}

  \newcommand*{\WidestContent}{ABCD}% <-- This should be the widest content
  \newcommand*{\TallestContent}{x^2}% <-- This should be the tallest content

  \newlength{\MyWidth}
  \settowidth{\MyWidth}{\WidestContent}% 

  \newcommand*{\ra}[1]{\overrightarrow{\mathmakebox[\MyWidth]{#1\vphantom{\TallestContent}}}}
  \newcommand*{\la}[1]{\overleftarrow{\mathmakebox[\MyWidth]{#1\vphantom{\TallestContent}}}}

 \begin{document}    
     $\la{x} \quad \la{x^2} \quad \ra{3xy} \quad \ra{ABCD}$
 \end{document}
| improve this answer | |
  • Or \mathmakebox. However the heights are not the same in the picture. – egreg Nov 25 '14 at 22:51
  • @egreg: Oh, I did not know about \mathmakebox -- Will have to look into that. Thanks for point out the slight difference in the height -- guess I have to resort to a \vphantom{}. – Peter Grill Nov 25 '14 at 22:53

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.