5

In this

\documentclass[12pt,a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\begin{document}
    \[
        \dfrac{\dfrac{a}{b}}{\dfrac{c}{d}}
    \]
    \[
        \dfrac{\dfrac{5}{12}}{\dfrac{6}{15}}
    \]
\end{document}

the fractions look very ugly, because the variables are too close to the middle fraction line. With only \frac{}{} and with numbers it looks even worse. I tried to fix it with a \raisebox but LaTeX complained (I guess it doesn't like \raiseboxes in math mode).

How can I add some space between the variables and the fraction lines?

And, while we are here, is there a way to make the middle fraction line a little longer, so that it's more obvious that it's a fraction with fractions above and below?

2
  • if you used \frac the inner fractions would be naturally smaller, you are forcing them all to use display style with \dfrac Sep 24, 2020 at 20:25
  • @DavidCarlisle Yes, I'm aware of that, but if I use \frac, then the fractions above and below look too small and they don't fit with the rest of the document (which I stripped out in order to make it a MWE).
    – Andyc
    Sep 24, 2020 at 20:34

2 Answers 2

5

\genfrac allows you to customise the rule width, and adding a thin space allows you to control the length as well. The space above and below the rule follows the rule width.

enter image description here

\documentclass[12pt,a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\newcommand\zfrac[2]{%
  \genfrac{}{}{1pt}{0}%
  {\mspace{1mu}#1\mspace{1mu}}{\mspace{1mu}#2\mspace{1mu}}}
\begin{document}
    \[
        \zfrac{\frac{a}{b}}{\frac{c}{d}}
    \]
    \[
        \zfrac{\frac{5}{12}}{\frac{6}{15}}
    \]
\end{document}
1
  • Now, that's very nice indeed.
    – Andyc
    Sep 24, 2020 at 20:38
4

Here's a solution that uses custom macro called \ddfrac ("double dfrac"), \Bstrut ("bottom strut"), and \Tstrut ("top strut").

enter image description here

\documentclass[12pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{mathtools} % for '\cramped' macro

\newcommand\ddfrac[2]{\frac{\displaystyle #1}{\cramped[\displaystyle]{#2}}}
\newcommand\Tstrut{\smash[b]{\strut}}
\newcommand\Bstrut{\smash[t]{\strut}}

\begin{document}
\[
\dfrac{\dfrac{5}{12}}{\dfrac{6}{15}}
\quad\text{vs.}\quad
\ddfrac{\frac{5}{12\Bstrut}}{\frac{6\Tstrut}{15}}
\]
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.