# Align fraction expanded parts

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)} \\ #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}


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

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. \documentclass{article} % or some other suitable document class
\usepackage{amsmath}    % for 'align*' environment
\usepackage{calc}
\newcommand\onebox{\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}


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} 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)} • Does the OP want to right-align the 1 symbols in row 2?
– Mico
Oct 15, 2021 at 12:49
• not sure what they want, just added the possible alternative Oct 15, 2021 at 12:53

May be something like that? \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