16

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:

enter image description here

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):

enter image description here

azetina
  • 28,884

5 Answers5

14

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

enter image description here

\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.

enter image description here

\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}
David Carlisle
  • 757,742
  • 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
12

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

enter image description here

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}

enter image description here

Aditya
  • 62,301
11

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:

enter image description here

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

enter image description here

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:

enter image description here

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}

Peter Grill
  • 223,288
  • 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
  • @azetina: Have provided a solution if you want that aligned as well. – Peter Grill Jun 13 '12 at 20:14
  • @Altermundus: Have fixed that as well. – Peter Grill Jun 13 '12 at 20:23
  • The last one is probably the way to go. However, \raisebox doesn't need graphicx. And I'm having a hard time in understanding why one should want such a thing. – egreg Jun 13 '12 at 20:24
  • @egreg What thing are you referring to? – azetina Jun 13 '12 at 20:28
  • @azetina That horrible parenthesized subformula. Maybe you have some reasons for wanting it, but I don't see which it can be. :) If you need to put that subformula into evidence, maybe enclosing it in a box with the help of the mighty \tikzmark could be better. – egreg Jun 13 '12 at 20:32
  • @egreg I guess that is the case but while the \tikzmark is a possibility I was looking for an immediate solution to the observed situation and use of the parenthesis. – azetina Jun 13 '12 at 20:35
5

The \scaleleftright[maxwidth]{left-delim}{term}{right-delim} macro provides scalable (not extensible) delimiters without forcing vertical height symmetry about \fracs. The optional parameter is a width limiter on the delimiters.

Note that the math axis of the fraction is not altered (as it is with a \raisebox), so the fraction's vinculum remains vertically aligned, automatically.

\documentclass[letterpaper]{article}
\usepackage{amsmath,scalerel}
\def\parenthis#1{\scaleleftright[1.5ex]{(}{#1}{)}}
\begin{document}
 $2-\frac{2}{1-\parenthis{\frac{2}{2-\frac{2}{x^2}}}}$\quad
 $2-\dfrac{2}{1-\parenthis{\dfrac{2}{2-\dfrac{2}{x^2}}}}$\quad
 $2-\cfrac{2}{1-\parenthis{\cfrac{2}{2-\cfrac{2}{x^2}}}}$\quad
 $2-\dfrac{2}{1-\parenthis{\cfrac{2}{2-\dfrac{2}{x^2}}}}$
\end{document}

enter image description here

2

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

\documentclass{article}
\usepackage{amsmath}
\makeatletter
\newcommand*{\adjust}[2][0pt]{\mathpalette\@djn{{#1}{#2}}}
\newcommand*{\@djn}[2]{%
\mbox{\raisebox{\@firstoftwo#2}{$#1\left(\raisebox{-\@firstoftwo#2}%
{$#1{\@secondoftwo#2}$}\right)$}}}  
\makeatother  

\begin{document}

\[
    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}}}}   
\]

\end{document} 

enter image description here

Alain Matthes
  • 95,075