12

I was trying to answer this question on another stackexchange forum, to say that they could use Latex instead, only to find I can't figure how to do this in Latex myself.

Is it possible to have 2 equations one in the numerator and one in denominator, be aligned at = in each? Here is MWE

\documentclass[12pt]{article}
\usepackage{amsmath}

\begin{document}

$\frac{\text{test} = 0.01}{\text{testing} = 0.01}$ \end{document}

Gives

enter image description here

I'd like these two to be aligned at =. Just like when one uses align* environment, except inside a fraction now.

\documentclass[12pt]{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
\text{test} &= 0.01 \\
\text{testing} &= 0.01
\end{align*}
\end{document}

enter image description here

TL 2022

Update Thanks for all the answers. Wish I can accept them all. I picked

\[
\begin{aligned}
\text{test}&=0.01 \\
\hline
\text{testing}&=0.01
\end{aligned}
\]

Because it was easiest for me to understand how it works. But all answers are really great.

Nasser
  • 20,220

4 Answers4

12

Use some \phantoms and overlapping:

enter image description here

\documentclass{article}

\usepackage{mathtools}

\begin{document}

$\frac{\text{test} = 0.01}{\text{testing} = 0.01}$

$\frac{\phantom{\text{testing}}\mathllap{\text{test}} = 0.01}{\text{testing} = 0.01}$

\end{document}

Werner
  • 603,163
9

One possibility is to use an array.

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\begin{document}
\begin{equation*}
\begin{array}{r@{}c@{}l}
\text{test}&{}={}&0.01 \\\hline
\text{testing}&{}={}&0.01
\end{array}
\end{equation*}
\end{document}

enter image description here

Ian Thompson
  • 43,767
7

Not to argue this as a preferred approach, but nonetheless, tabstackengine can achieve the desired result.

\documentclass[12pt]{article}
\usepackage[TABcline]{tabstackengine}
\usepackage{amsmath}
\stackMath
\begin{document}
\[
\setstackgap{S}{1pt}
\vcenter{\hbox{\alignShortstack{
\text{test} \mathstrut=& 0.01 \\
\TABcline{1-2}
\text{testing} \mathstrut=& 0.01}}} = 0
\]
\end{document}

enter image description here

7

This is, of course, not a fraction. But it's easy to emulate one.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

[ \begin{aligned} \text{test}&=0.01 \ \hline \text{testing}&=0.01 \end{aligned} = \frac{0.01}{0.01} ]

\end{document}

enter image description here

The spacing is not exactly the same, though.

Just for fun.

\documentclass{article}
\usepackage{amsmath}
\usepackage{booktabs}

\begin{document}

[ \setlength{\aboverulesep}{0.14ex} \setlength{\belowrulesep}{0.22ex} \begin{aligned} \addlinespace[0.04ex] \text{test}&=0.01 \ \midrule[0.4pt] \text{testing}&=0.01 \end{aligned} = \frac{0.01}{0.01} ]

\end{document}

enter image description here

egreg
  • 1,121,712