3

I have the following code in my document:

$$ \frac{\displaystyle \sum_i \min(A_i,B_i)}
        {\displaystyle \sum_i \max(A_i,B_i)} $$

resulting in:
                                                enter image description here
I prefer "display style" here, but the size of the contents in the numerator and denominator are a bit too large for my liking in the context where they appear, so I decided to scale down.

$$ \frac{\scalebox{0.75}{\text{$\displaystyle \sum_i \min(A_i,B_i)$}}}
        {\scalebox{0.75}{\text{$\displaystyle \sum_i \max(A_i,B_i)$}}} $$

but for some reason, this causes an unwanted shift:

                                                 enter image description here

so I'm forced to go back to standard "text style" mode in the meantime...

I can't spot why this might be happening based on the code above; I've also tried resizebox but it has the same issue ... has anyone got any idea why it's happening or how I could fix it?

(EDIT: I solved my particular problem by scaling down the fraction as a whole rather than its constituent parts; but the question remains. Is this a latex bug? Thanks.)

4
  • 1
    You probably want \frac{\sum\limits_i \min(A_i,B_i)}{\sum\limits_i \max(A_i,B_i)}.
    – egreg
    Commented Sep 5, 2016 at 14:06
  • Also, avoid $$....$$
    – JPi
    Commented Sep 5, 2016 at 14:17
  • See Why is \[ … \] preferable to $$?
    – egreg
    Commented Sep 5, 2016 at 14:38
  • fair enough, thanks for the link; \[ ... \] is irrelevant here though. Commented Sep 5, 2016 at 15:43

2 Answers 2

4

In my opinion you don't really want \displaystyle, but neither you want \scalebox.

The size of \min and the other letters is right, it's just the summation symbol that grow too large:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\frac{\sum\limits_i \min(A_i,B_i)}
     {\sum\limits_i \max(A_i,B_i)}
\qquad
\frac{\displaystyle\sum_i \min(A_i,B_i)}
     {\displaystyle\sum_i \max(A_i,B_i)}
\]
\end{document}

enter image description here

If you really want to go the \scalebox way, enclose them in \mbox:

\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}
\begin{document}
\[
\frac{\mbox{\scalebox{0.75}{$\displaystyle \sum_i \min(A_i,B_i)$}}}
     {\mbox{\scalebox{0.75}{$\displaystyle \sum_i \max(A_i,B_i)$}}}
\]
\end{document}

The issue is apparently due to how TeX typesets fractions, putting aside the numerator until it decides the size; the assignments performed by \scalebox get wrong without this further level of boxing.

Or, maybe better, use \mfrac from the nccmath package:

\documentclass{article}
\usepackage{amsmath}
\usepackage{nccmath}
\begin{document}
\[
\mfrac{\displaystyle \sum_i \min(A_i,B_i)}
      {\displaystyle \sum_i \max(A_i,B_i)}
\qquad
\frac{\displaystyle \sum_i \min(A_i,B_i)}
      {\displaystyle \sum_i \max(A_i,B_i)}
\]
\end{document}

enter image description here

1
  • All excellent suggestions, and good explanation. Thank you very much. Commented Sep 5, 2016 at 16:07
5

can you try this:

\documentclass{article}
\usepackage{graphicx}
\makeatletter
\long\def\Gscale@box#1[#2]#3{%
  \leavevmode
  \hbox\bgroup%<<<<<<<<
  \def\Gscale@x{#1}\def\Gscale@y{#2}%
  \setbox\z@\hbox{{#3}}%
  \setbox\tw@\hbox{\Gscale@start\rlap{\copy\z@}\Gscale@end}%
  \ifdim#2\p@<\z@
    \ht\tw@-#2\dp\z@
    \dp\tw@-#2\ht\z@
  \else
    \ht\tw@#2\ht\z@
    \dp\tw@#2\dp\z@
  \fi
  \ifdim#1\p@<\z@
    \hb@xt@-#1\wd\z@{\kern-#1\wd\z@\box\tw@\hss}%
  \else
    \wd\tw@#1\wd\z@
    \box\tw@
  \fi
  \egroup%<<<<<<<<
}

\begin{document}

\[
\frac{\scalebox{0.75}{$\displaystyle \sum_i \min(A_i,B_i)$}}
     {\scalebox{0.75}{$\displaystyle \sum_i \max(A_i,B_i)$}}
\]
\end{document}
5
  • This indeed fixes the odd behaviour, though I will admit it's a bit beyond my TeX skills so I don't quite follow it :) I decided to accept egreg's answer instead since that addresses my problem a bit more intuitively, but thank you for this answer! Commented Sep 5, 2016 at 16:11
  • @TasosPapastylianou see chat.stackexchange.com/transcript/message/32124111#32124111 :-) Commented Sep 5, 2016 at 16:12
  • ahahahah. I'm sorry I'm sorry I'm sorry xD Commented Sep 5, 2016 at 16:28
  • 1
    @TasosPapastylianou I'll add the above fix to graphics at the next release, so then the extra box in the document as in egreg's version won't be needed (but won't do any harm) Commented Sep 5, 2016 at 16:31
  • Glad to hear it! For the record, I don't know if this makes you more or less grumpy, hahah, but I used neither solution since I already 'solved' my problem as described in my edited question :p Glad to hear my question ended up being of some use though! Commented Sep 5, 2016 at 16:33

You must log in to answer this question.

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