9

Is there a way to make the fraction line look like the equality (=) sign, i.e., to have two parallel horizontal lines with a little gap in between? Many thanks!

1
  • 8
    As a matter of curiosity what does this represent? Disclaimer, mathematically curious but not a mathematician. May 16, 2012 at 6:15

2 Answers 2

13

Use either \Tfrac or \Dfrac (short for Text and Display style "equal fraction") in the following:

enter image description here

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\newcommand{\Tfrac}[2]{%
  \ooalign{%
    $\genfrac{}{}{1.2pt}1{#1}{#2}$\cr%
    $\color{white}\genfrac{}{}{.4pt}1{\phantom{#1}}{\phantom{#2}}$}%
}
\newcommand{\Dfrac}[2]{%
  \ooalign{%
    $\genfrac{}{}{1.2pt}0{#1}{#2}$\cr%
    $\color{white}\genfrac{}{}{.4pt}0{\phantom{#1}}{\phantom{#2}}$}%
}
\begin{document}
$f(x)=\Tfrac{1}{2}+\frac{1}{2}$
\end{document}

For a short course on \ooalign, see \subseteq + \circ as a single symbol (“open subset”).


Here is a slightly modified set of commands: \Efrac and \efrac. While both adjust their fraction size based on the math style automatically (using \mathchoice), the former is vertically higher (set based on the height of the two outer black fraction lines) than the latter (set based on the height of a regular fraction).

enter image description here

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\newcommand{\Efrac}[2]{%
  \mathchoice
    {\ooalign{%
      $\genfrac{}{}{1.2pt}0{#1}{#2}$\cr%
      $\color{white}\genfrac{}{}{.4pt}0{\phantom{#1}}{\phantom{#2}}$}}%
    {\ooalign{%
      $\genfrac{}{}{1.2pt}1{#1}{#2}$\cr%
      $\color{white}\genfrac{}{}{.4pt}1{\phantom{#1}}{\phantom{#2}}$}}%
    {\ooalign{%
      $\genfrac{}{}{1.2pt}2{#1}{#2}$\cr%
      $\color{white}\genfrac{}{}{.4pt}2{\phantom{#1}}{\phantom{#2}}$}}%
    {\ooalign{%
      $\genfrac{}{}{1.2pt}3{#1}{#2}$\cr%
      $\color{white}\genfrac{}{}{.4pt}3{\phantom{#1}}{\phantom{#2}}$}}%
}
\newcommand{\efrac}[2]{%
  \mathchoice
    {\ooalign{%
      $\genfrac{}{}{1.2pt}0{\hphantom{#1}}{\hphantom{#2}}$\cr%
      $\color{white}\genfrac{}{}{.4pt}0{\color{black}#1}{\color{black}#2}$}}%
    {\ooalign{%
      $\genfrac{}{}{1.2pt}1{\hphantom{#1}}{\hphantom{#2}}$\cr%
      $\color{white}\genfrac{}{}{.4pt}1{\color{black}#1}{\color{black}#2}$}}%
    {\ooalign{%
      $\genfrac{}{}{1.2pt}2{\hphantom{#1}}{\hphantom{#2}}$\cr%
      $\color{white}\genfrac{}{}{.4pt}2{\color{black}#1}{\color{black}#2}$}}%
    {\ooalign{%
      $\genfrac{}{}{1.2pt}3{\hphantom{#1}}{\hphantom{#2}}$\cr%
      $\color{white}\genfrac{}{}{.4pt}3{\color{black}#1}{\color{black}#2}$}}%
}
\begin{document}
\[ f(x)={\textstyle\Efrac{1}{2}+\frac{1}{2}} \sim \Efrac{3}{4}+\frac{3}{4} \]
\[ f(x)={\textstyle\efrac{1}{2}+\frac{1}{2}} \sim \efrac{3}{4}+\frac{3}{4} \]
\end{document}
3
  • I accidentally made a duplicate here— tex.stackexchange.com/questions/295739/…—because when I searched for existing answers I looked for "double bar" or "double slash." I would like to know how to modify this answer a bit to play with spacing, if you have a moment. Particularly, I'd like to be able to change the spaces between the numerator and denominator and the pair of lines, and the space between the two lines. How could I do that?
    – jdc
    Feb 25, 2016 at 1:10
  • 2
    The above approach prints the fraction twice: first with a very thick 1.2pt rule, then overprints it with a thin white .4pt rule that also sets the numerator #1 and denominator #2. Since \genfrac is vertically centered on the math axis, the overprinting of the thin white on thick black rule leaves a .4pt black rule at the top and bottom. If you want a thicker rule, you can adjust the 1.2pt value and/or .4pt value.
    – Werner
    Feb 25, 2016 at 6:47
  • I found a solution by printing the \genfrac 3 times, 2 with phantoms, so I can exactly control the spacing between the denom and nom. Aug 9, 2018 at 17:38
3

A solution without colors, which could break in case of colored background.

The fraction is typeset twice: the first time it is raised and the denominator is a phantom; the second time it is lowered and the numerator is a phantom. The two are superimposed with the help of \ooalign.

The gap is customizable with the parameter \doublefracgap.

\documentclass{article}
\usepackage[fleqn]{amsmath}

\makeatletter
\newlength{\doublefracgap}
\setlength{\doublefracgap}{0.75pt}
\DeclareRobustCommand{\doublefrac}[2]{%
  \mathinner{\mathpalette\doublefrac@{{#1}{#2}}}%
}
\newcommand{\doublefrac@}[2]{\doublefrac@@#1#2}
\newcommand{\doublefrac@@}[3]{%
  \ooalign{%
    \raisebox{\doublefracgap}{$\m@th#1\frac{#2}{\phantom{#3}}$}\cr
    \raisebox{-\doublefracgap}{$\m@th#1\frac{\phantom{#2}}{#3}$}\cr
  }%
}
\newcommand{\ddoublefrac}[2]{{\displaystyle\doublefrac{#1}{#2}}}
\newcommand{\tdoublefrac}[2]{{\textstyle\doublefrac{#1}{#2}}}
\makeatother

\setlength{\mathindent}{0pt} % just for the example
\setlength{\parindent}{0pt} % just for the example

\begin{document}

\[
\doublefrac{1}{2}\ne\frac{1}{2} \qquad \sqrt{\doublefrac{x^2+2}{x^2-1}}
\]
\[
\frac{1}{2}\ne\doublefrac{1}{2}
\]
$\doublefrac{1}{2}\ne\frac{1}{2}$

$\frac{1}{2}\ne\doublefrac{1}{2}$

$\ddoublefrac{1}{2}\ne\dfrac{1}{2}$

$\dfrac{1}{2}\ne\ddoublefrac{1}{2}$

\end{document}

enter image description here

1
  • Looking at the various fractions the presence of the double fraction lines increases the distance. You can see that, for example, the number 1 with the fraction of the double lines does not line up with the number 1 of the classic fraction line. +1
    – Sebastiano
    Oct 27, 2021 at 23:02

You must log in to answer this question.

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