1

The oveleft/rightarrow-command is not optimal because it shiftes indices to much to the right in formulas like:

$\overleftarrow{D}_v$

Therefore, I use the following macro which I have adapted from some answer on this site a while ago. (Sorry, I cannot give credit to the author of the code because I forgot where I read it.)

\usepackage{stackengine}
\newcommand\constantoverleftarrow[1]{\stackengine{0pt}{$\overleftarrow{\hphantom{D}\vphantom{#1}}$}{$#1$}{O}{l}{F}{F}{L}}

The command

$\constantoverleftarrow{D_v}$

then gives the desired result. So far so good. Now, I want to align the subscripts as in the follwing code:

$\constantoverleftarrow{D_{v'\vphantom{\scalebox{0.73}{$\int$}}}}x_{v,v'}^d$

If you use

$\constantoverleftarrow{D_{v'}}x_{v,v'}^d$

instead, you will see that the v's and the v''s in the subscripts are not properly aligned. With the naked eye, I chose the value 0.73 in the scalebox to more or less achieve what I want.

Can someone please tell me how I do this properly? I hardly want to choose for each formula a value in the scalebox, as you can imagine. Because this takes incredibly much time. Also, I want the alignement to be perfect and not only approximative. How can I achieve this?

I tried several things now and was not able to do it. There are many questions like this on the site. But I was not able to find a solution. Note, I want the arrow over the D not shifted upwards or anything like this.

Related.

165499, 174122, 354871.

MWE.

\documentclass[12pt]{amsart}
\usepackage{stackengine}
\newcommand\constantoverleftarrow[1]{\stackengine{0pt}{$\overleftarrow{\hphantom{D}\vphantom{#1}}$}{$#1$}{O}{l}{F}{F}{L}}
\begin{document}
\[
\constantoverleftarrow{D_{v'}}x_{v,v'}^d
\]
\end{document}

This MWE repdocues indeed the error. You see, the indices are not aligned. Only if you add the integral. The problem is caused by the d in the superscript as I noticed now while playing around. I am sorry that I forgot the d in my initial post.

Possible solution for the right result.

\documentclass[12pt]{amsart}
\usepackage{stackengine}
\newcommand\constantoverleftarrow[1]{\stackengine{0pt}{$\overleftarrow{\hphantom{D}\vphantom{D}}$}{$#1$}{O}{l}{F}{F}{L}}
\newcommand{\nhphantom}[1]{\setbox0=\hbox{#1}\hspace{-\the\wd0}}
\begin{document}
%This is not perfect because the space between $D$ and the subscript $v'$ is not exactly like in $D_{v'}$ but almost and slightly smaller. The indices are however aligned. The best I can do.
\[
\constantoverleftarrow{D\nhphantom{$\displaystyle x_{}^{}$}\phantom{x}_{\vphantom{,}v'}^{\vphantom{d}}}x_{v,v'}^d
\]
\end{document}
7
  • It is a little difficult to make out what you're asking. Could you turn your code fragments into a proper MWE? It should start with \documentclass, and end with \end{document} and should load the minimum number of packages that you need to illustrate the problem. (And it should compile.) Jul 6, 2018 at 13:55
  • Yes, I should do this later because in the pictures below it looks great but in my file the results are not ok. @Circumscribe Jul 6, 2018 at 14:11
  • Ah, I see. The different depths of the subscript is due to the presence of a superscript (the ^d). I believe the supdepth package "fixes" this. (See this answer.) Jul 6, 2018 at 14:36
  • subdepth with option low-sup does the job. Strangely enough, it only work inbetween \[...\] but not inbetween $...$. Jul 6, 2018 at 14:53
  • The low-sup option is buggy, I think it doesn't work in inline equations with superscript that stick out below the baseline. The only fix I know involves redefining ^, and I'm not sure I should be recommending that since it is a rather drastic thing to do. I don't really know how the package works though, so there might very well be better ways to fix that problem. Jul 6, 2018 at 16:22

3 Answers 3

2

Because an MWE has not been provided, it is not exactly clear what the issue is. But here is a stab...at something.

\documentclass{article}
\usepackage{stackengine,graphicx}
\newcommand\constantoverleftarrow[1]{\cola#1\endcola}
\def\cola#1#2\endcola{\stackengine{0pt}{}{$\overleftarrow{#1}$}{O}{l}{F}{T}{L}%
  \phantom{#1}#2}
\begin{document}
$\overleftarrow{D}_v$

$\constantoverleftarrow{D_v}$

$\constantoverleftarrow{D_{v'}}x_{v,v'}$
\end{document}

enter image description here

2
  • @John Kormylo and @Seven B. Segletes Thank you a lot! I appreciate your help! This is really great. I think you understood the issue very well. I can see that is working. But I don't understand why. Where do you set the horizontal length of the arrow to be equal to D? I ask so that I can modify in other formulas in case I need it. Jul 6, 2018 at 13:58
  • @user66288 The $\overleftarrow{#1}$ is what typesets the overarrowed D, since #1 is the first token of your argument. Later in the definition, the \phantom{#1} skips by the width of a D, so that the subscript can be set as if were next to the plain letter. Jul 6, 2018 at 14:16
1

I suggest using smaller arrows (like in https://tex.stackexchange.com/a/248297/4427)

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newcommand{\overleftsmallarrow}{\mathpalette{\overarrowsmall@\leftarrowfill@}}
\newcommand{\overrightsmallarrow}{\mathpalette{\overarrowsmall@\rightarrowfill@}}
\newcommand{\overleftrightsmallarrow}{\mathpalette{\overarrowsmall@\leftrightarrowfill@}}
\newcommand{\overarrowsmall@}[3]{%
  \vbox{%
    \ialign{%
      ##\crcr
      #1{\smaller@style{#2}}\crcr
      \noalign{\nointerlineskip\vskip0.4pt}%
      $\m@th\hfil#2#3\hfil$\crcr
    }%
  }%
}
\def\smaller@style#1{%
  \ifx#1\displaystyle\scriptstyle\else
    \ifx#1\textstyle\scriptstyle\else
      \scriptscriptstyle
    \fi
  \fi
}
\makeatother

\begin{document}

$\overrightsmallarrow{D}_v$ $\overleftsmallarrow{D}_v$ $\overleftrightsmallarrow{D}_v$

$D_v$ $D_v$ $D_v$
\end{document}

enter image description here

1

Note that \oveleftarrow is centered while subscripts and superscripts are not.

Note that this is math style dependent. That can be fixed with a lot more effort. See here.

\documentclass{article}
\usepackage{mathtools}

\newcommand{\combine}[3]% #1=centered preop, #2=operand, #3=postop
{\bgroup
  \sbox0{$#1{\phantom{#2}}$}%
  \sbox1{$#2$}%
  \usebox0\hspace{-0.5\wd0}\hspace{-0.5\wd1}\usebox1\hspace{-\wd1}\phantom{#2}#3
\egroup}

\begin{document}
$\overleftarrow{D} D_v \combine{\overleftarrow}{D}{_v}$

\end{document}

demo

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .