3

I was checking the solution here

for make a small fraction. I get the fraction but I noticed that there is a variation in the vertical alignment in display mode and inline mode:

enter image description here

\documentclass[12pt]{memoir}

\usepackage{amsmath}
 \usepackage{graphicx}
\usepackage{stackengine}

\newcommand{\smath}[1]{\text{\scalebox{0.95}{$#1$}}}

\newcommand{\myfrac}[3][0pt]{\belowbaseline[-.65\baselineskip]{\smath{\genfrac{}{}{}{3}{\raisebox{#1}{$#2$}}{\raisebox{-#1}{$#3$}}}}}


\begin{document}
$\tanh\Bigl(\myfrac{\alpha}{2}\Bigr)$ 

\begin{align}
    \tanh\Bigl(\myfrac{\alpha}{2}\Bigr)
\end{align}

\end{document}

As you can see in display mode the fraction is moved up a little bit. This doesn't happen with equation environment nor \[ \]. What am I doing wrong?

14
  • \frac works fine. Nor is \scalebox the culprit. This looks llike a bug in \genfrac (stackengine). Apr 3, 2021 at 15:08
  • Oh well, I was looking for a small frac, because that I defined another "frac". I add information.
    – juanuni
    Apr 3, 2021 at 18:38
  • 1
    @JohnKormylo -- genfrac is defined in amsmath; I don't think it's redefined in stackengine. Apr 3, 2021 at 19:17
  • @juanuni -- align should give exactly the same result as equation. But Id be inclined to use \dfrac` instead of trying to define something else. Apr 3, 2021 at 19:24
  • @barbarabeeton well I was looking for another small fraction, just that. Maybe I shouldn't try with small fraction in display mode.
    – juanuni
    Apr 3, 2021 at 19:26

2 Answers 2

1

The problem is that the definition of \myfrac makes use of \baselineskip, whose value is reset in amsmath environments. The solution? Use \normalbaselineskip in the definition of \myfrac instead.

In fact, the default baselineskip for long stacks in the stackengine package is \normalbaselineskip, for precisely this reason.

\documentclass[12pt]{memoir}

\usepackage{amsmath}
 \usepackage{graphicx}
\usepackage{stackengine}

\newcommand{\smath}[1]{\text{\scalebox{0.95}{$#1$}}}

\newcommand{\myfrac}[3][0pt]{\belowbaseline[-.65\baselineskip]{\smath{\genfrac{}{}{}{3}{\raisebox{#1}{$#2$}}{\raisebox{-#1}{$#3$}}}}}
\begin{document}
OK with non-amsmath
\[
    \tanh\Bigl(\myfrac{\alpha}{2}\Bigr)---\the\baselineskip
\]
In vertical alignment error with amsmath
\begin{align}
    \tanh\Bigl(\myfrac{\alpha}{2}\Bigr)---\the\baselineskip
\end{align}
Why? amsmath redefines \textbackslash baselineskip.\\
Solution? Use \textbackslash normalbaselineskip
\renewcommand{\myfrac}[3][0pt]{\belowbaseline[-.65\normalbaselineskip]{\smath{\genfrac{}{}{}{3}{\raisebox{#1}{$#2$}}{\raisebox{-#1}{$#3$}}}}}%
\begin{align}
    \tanh\Bigl(\myfrac{\alpha}{2}\Bigr)---\the\normalbaselineskip
\end{align}
\end{document}

enter image description here

4
  • Good diagnosis. But in the third instance (presumably using \normalbaselineskip), the fraction line appears to actually cut through the top of the 2. (In all instances, I think it's too close, but assume that's subjective. But intersecting can't be correct.) However, the fraction line is definitely in the same vertical position as the math axis, which is what is wanted. Apr 8, 2021 at 1:45
  • @barbarabeeton That is how the OP defined it to begin with, to get a close fraction. I didn't pick up on that, but my reading of the question was that it was all about why the vertical shift occurred. I'll see if it is just font hinting, or actual Apr 8, 2021 at 1:55
  • @barbarabeeton I have confirmed that your perception arises from the resolution of the image. Under zoom, all denominators lie at the same relative position to the fraction bar. Apr 8, 2021 at 1:59
  • @StevenB.Segletes thanks a lot.For the fraction line a put \mathstrut inside each \raisebox just before $2$ and $3$, respectively.
    – juanuni
    Apr 18, 2021 at 17:47
1

While \scalebox{0.95}{...} is not a major problem \scalebox{0.5}{...} would be. When you scale an image, only one point is not moved, which for \scalebox turns out to be the left baseline.

In the following I move the baseline to the center, scale it, then move the baseline back again.

\documentclass[12pt]{memoir}

\usepackage{amsmath}
 \usepackage{graphicx}
%\usepackage{stackengine}

\fboxsep=0pt

\newcommand{\smath}[1]{\raisebox{\dimexpr 0.5\ht\strutbox-0.5\dp\strutbox}%
  {\scalebox{0.5}{\raisebox{\dimexpr 0.5\dp\strutbox-0.5\ht\strutbox}{$#1$}}}}

\newcommand{\myfrac}[3][0pt]{\smath{\tfrac{#2}{#3}}}

\begin{document}
$\tanh\Bigl(\myfrac{\alpha}{2}\Bigr) {\displaystyle \tanh\Bigl(\myfrac{\alpha}{2}\Bigr)}$

\begin{align}
    \tanh\Bigl(\myfrac{\alpha}{2}\Bigr)
\end{align}

\end{document}
2
  • I appreciate your time to write an answer. Your suggestion, elegant by the way, doesn't go in the direction of my question.In your suggestion I was trying with \scalebox{0.75}{...} and without \Big for parenthesis. I saw the fraction and the parenthesis was aligned at the bottom of the line. I was looking for move up the fraction a little bit so the fraction and parenthesis was centered vertically (I hope write this adequately). Because that I used \belowbaseline[-.65\baselineskip]{{...} and I noticed that inline mode and with align environment the vertical shift isn't the same, and
    – juanuni
    Apr 6, 2021 at 16:37
  • ... that's what I was trying to solve. I hope I have written well because English is not my native language.
    – juanuni
    Apr 6, 2021 at 16:37

You must log in to answer this question.

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