TransWikia.com

How to add space between variables and fraction lines

TeX - LaTeX Asked by Andyc on December 30, 2020

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 Answers

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}

newcommandzfrac[2]{%
  genfrac{}{}{1pt}{0}%
  {mspace{1mu}#1mspace{1mu}}{mspace{1mu}#2mspace{1mu}}}
begin{document}
    [
        zfrac{frac{a}{b}}{frac{c}{d}}
    ]
    [
        zfrac{frac{5}{12}}{frac{6}{15}}
    ]
end{document}

Correct answer by David Carlisle on December 30, 2020

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

newcommandddfrac[2]{frac{displaystyle #1}{cramped[displaystyle]{#2}}}
newcommandTstrut{smash[b]{strut}}
newcommandBstrut{smash[t]{strut}}

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

Answered by Mico on December 30, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP