# Proper display of fractions

Have a look at the following code:

\documentclass[letterpaper]{article}
\usepackage{amsmath,amssymb}
\begin{document}
$2-\frac{2}{1-\left(\frac{2}{2-\frac{2}{x^2}}\right)}$\quad
$2-\dfrac{2}{1-\left(\dfrac{2}{2-\dfrac{2}{x^2}}\right)}$\quad
$2-\cfrac{2}{1-\left(\cfrac{2}{2-\cfrac{2}{x^2}}\right)}$\quad
$2-\dfrac{2}{1-\left(\cfrac{2}{2-\dfrac{2}{x^2}}\right)}$
\end{document}


This gives:

Evidently, the first display is not the proper way. The second and last are the same I guess. The third has a better display but there is too much space above the 2 in \left(\cfrac{2}{2-\cfrac{2}{x^2}}\right). Essentially, non of the above displays satisfies, for me, a good Mathematical typsetting. Although, it may be argued that it is the default in LaTeX. I just can't get it right? Any insights? In a book I got this example from it looks like this without the excessive bold (this is a scanned image):

-
–  Hendrik Vogt Jun 13 '12 at 19:52
And why not : $\displaystyle 2-\frac{2}{1-\left(\frac{2}{2-\frac{2}{x^2}}\right)}$ –  Alain Matthes Jun 13 '12 at 19:57
@Altermundus Nah, the part \left(\frac{2}{2-\frac{2}{x^2}}\right) looks to compressed. Isn't it? –  azetina Jun 13 '12 at 20:00
I'd change the title into "Improper use of parentheses". :) –  egreg Jun 13 '12 at 20:25
I must confess I don't understand why you're using parentheses in the first place. Without the parentheses, the output looks perfectly readable and you don't have any issues with raising or lowering stuff. –  Mico Jun 13 '12 at 20:26

You can use \raisebox{<length>}{<text> to shift the content up as desired.

So using it to shift up the content with in the large brackets you get:

$2-\frac{2}{1-\left(\raisebox{0.5ex}{\displaystyle\frac{2}{2-\frac{2}{x^2}}}\right)}$


you get:

If you also want the 1 - to be aligned with the fraction's vinculum, you can apply \raisebox to that as well:

I personally think the above looks the best, but if you desire the last fraction in \displaystyle as well then the fraction size increases and the shift amount applied by \raisebox also needs to be increased:

## Note:

• \raisebox expects text as its parameter so you need to put that content within math mode.

## Code:

\documentclass{article}
\usepackage{amsmath}

\begin{document}
$2-\frac{2}{1-\left(\raisebox{0.5ex}{\displaystyle\frac{2}{2-\frac{2}{x^2}}}\right)}$
If you want the minus sign aligned with the fraction:
$2-\frac{2}{\raisebox{0.5ex}{1-}\left(\raisebox{0.5ex}{\displaystyle\frac{2}{2-\frac{2}{x^2}}}\right)}$
If you want the last fraction to be in
\verb|\displaystle| as well:
$2-\frac{2}{\raisebox{1.1ex}{1-}\left(\raisebox{1.1ex}{\dfrac{2}{2-\dfrac{2}{x^2}}}\right)}$
\end{document}

-
I'd add \displaystyle in the inner formula –  egreg Jun 13 '12 at 20:02
@egreg: Thanks for pointing that out. Have corrected. –  Peter Grill Jun 13 '12 at 20:06
But using \raisebox moves the fraction line in \frac{2}{2-\frac{2}{x^2}} by the specified amount, right? –  azetina Jun 13 '12 at 20:06
Sorry, but this is still incorrect: the last fraction should be in displaystyle too. Probably \dfrac from amsmath, or directly \cfrac. But perhaps also the 1- needs to be raised, then, to bring it at the same height as the main fraction line. The output is ugly nonetheless. –  egreg Jun 13 '12 at 20:10
This is horrible, the fraction bar is not aligned with the minus symbol in the denominator! –  Alain Matthes Jun 13 '12 at 20:13

I think it's just enough to hide the depth of the inner fraction rather fall back on explicit positioning.

\documentclass{article}
\usepackage{amsmath}
\begin{document}

$\displaystyle 2-\dfrac{2}{1-\left(\dfrac{2}{\smash{2-\frac{2}{x^2}}}\right)}$

\end{document}


Or this version, which uses displaystyle throughout and preserves the vertical alignment of fraction bar and minus sign by putting the brackets around the whole lower expression, and then backspacing the "1-" outside the brackets.

\documentclass{article}
\usepackage{amsmath}
\begin{document}

$\displaystyle 2-\dfrac{2}{\phantom{1-{}}\left( \vcenter{\hbox{\llap{$\displaystyle1-{}$\kern1em}$\displaystyle\dfrac{2}{2-\dfrac{2}{x^2}}$}} \right)}$

\end{document}

-
But the \frac{2}{x^2} is not in display mode. –  azetina Jun 13 '12 at 20:15
well you can use \dfrac for the inner fraction as well, I just thought at some point you might like to let the font shrink. actually you can't (it overprints, may post a version latter, got to go now) –  David Carlisle Jun 13 '12 at 20:25

FWIW, the nath package correctly scales the delimiters:

\documentclass{standalone}
\usepackage{nath}
\begin{document}
\begin{equation*}
2-\frac{2}{1-(\frac{2}{2-\frac{2}{x^2}})}
\end{equation*}
\end{document}


gives

More interestingly, it automatically changes the display fractions to inline fractions when you used in inline math mode:

\documentclass{standalone}
\usepackage{nath}
\begin{document}
$2-\frac{2}{1-(\frac{2}{2-\frac{2}{x^2}})}$
\end{document}


-

A solution from an answer of Jean Côme Charpentier on fr.comp.text.tex

\documentclass{article}
\usepackage{amsmath}
\makeatletter
\mbox{\raisebox{\@firstoftwo#2}{$#1\left(\raisebox{-\@firstoftwo#2}% {$#1{\@secondoftwo#2}$}\right)$}}}
$2-\frac{2}{1-\left(\frac{2}{2-\frac{2}{x^2}}\right)} \longrightarrow 2-\frac{2}{1- \adjust[-2pt]{\frac{2}{2-\frac{2}{x^2}}}}$