2

I want to make it easier to see how a fraction has been expanded. I used \hfill to separate the expanded parts, but the "1s" are not in the center anymore.

How can I achieve this?

&= \frac{1}{x-y} - \frac{1}{y-x} \\
&= \frac{1\hfill*(y-x)}{(x-y)*(y-x)} - \frac{1\hfill*(x-y)}{(y-x)*(x-y)} \\

enter image description here

#edit: complete code for compiling

\documentclass{article}
\usepackage{amsmath}

\begin{document} \begin{align} &= \frac{1}{x-y} - \frac{1}{y-x} \ &= \frac{1\hfill(y-x)}{(x-y)(y-x)} - \frac{1\hfill(x-y)}{(y-x)(x-y)} \ \end{align} \end{document}

TheName
  • 23
  • Welcome to TeX.SE :) // Unfortunately nobody can copy your code and compile it. So please complete it, first. Thanks. – MS-SPO Oct 15 '21 at 12:13
  • Unrelated to LaTeX, but don't you think the computation could be done in a simpler way? – Bernard Oct 15 '21 at 13:44

3 Answers3

2

I suggest you place the 1 in the numerator in a centered \parbox whose width is given by the first expression in the denominator. In the example below, that's done with the help of a macro called \onebox.

I would also consider replacing the * multiplication symbols with \cdot.

enter image description here

\documentclass{article} % or some other suitable document class
\usepackage{amsmath}    % for 'align*' environment
\usepackage{calc}
\newcommand\onebox[1]{\parbox{\widthof{$\textstyle #1$}}{\centering $1$}}
\begin{document}

\begin{align} &= \frac{1}{x-y} - \frac{1}{y-x} \ &= \frac{\onebox{(x-y)}(y-x)}{(x-y)(y-x)} - \frac{\onebox{(y-x)}(x-y)}{(y-x)(x-y)} \end{align}

\begin{align} &= \frac{1}{x-y} - \frac{1}{y-x} \ &= \frac{\onebox{(x-y)}\cdot(y-x)}{(x-y)\cdot(y-x)} - \frac{\onebox{(y-x)}\cdot(x-y)}{(y-x)\cdot(x-y)} \end{align}

\end{document}

Mico
  • 506,678
1

This seems to be what you want.

\documentclass{article}
\usepackage{mathtools}

\begin{document}

\begin{align} foo &= bar \ &= \frac{1}{x-y} - \frac{1}{y-x} \ &= \frac{\hfill 1(y-x)}{(x-y)(y-x)} - \frac{\hfill 1(x-y)}{(y-x)(x-y)} \end{align}

\end{document}

output

Simply place \hfill before the 1 rather than after it.


edit per Mico's comment: if you want the 1 centered in to first "column", you can place another \hfill after it

\frac{\hfill1\hfill*(y-x)}{(x-y)*(y-x)}

alternative output

plante
  • 1,349
0

May be something like that?

enter image description here

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat*}{3}
&= \hspace{0.9 cm}\frac{1}{x-y}     &&-\hspace{0.9 cm} \frac{1}{y-x} \\
&= \frac{1\cdot(y-x)}{(x-y)\cdot(y-x)} &&- \frac{1\cdot(x-y)}{(y-x)\cdot(x-y)} \\
\end{alignat*}
\end{document
WinnieNotThePooh
  • 3,008
  • 1
  • 7
  • 14