I am looking to keep the comments on the side so I don't want an intertext or short intertext but make the long line two lines and keep everything equally spaced! What is the trick/ command?

\documentclass{article}
\usepackage{amsmath,xcolor,geometry}
\begin{document}
\begin{aligned}[t] \dfrac{20-5x^{2}}{x^{2}+x-6}&=\dfrac{5(4-x^{2})}{(x+3) (x-2)} && \textcolor{blue}{\text{Factor}} \\ &=\dfrac{5(2+x)(2-x)} {(x+3)(x-2)} && \textcolor{blue}{\text{Factor completely}} \\ &=\dfrac{5(2+x) \cdot \textcolor{red}{-1}(\colorbox{cyan!25!white}{x-2$})} {(x+3)(\colorbox{cyan!25!white}{$x-2$})} && \textcolor{blue}{\text{Notice opposites in$2-x$and$x-2$. Write$2-x$as$-1(x-2)and simplify}} \\ &=-\dfrac{5(2+x)}{x+3} \end{aligned}
\end{document}


Here's something that I do in such cases.

\documentclass{article}

\usepackage{amsmath,xcolor,geometry}

\newbox\aebox
\newcommand\aecomment[1]{%%
\begin{lrbox}\aebox
\begin{minipage}[t]{2in}
\raggedright
\textcolor{blue}{#1}%%
\end{minipage}%%
\end{lrbox}%%
\raisebox{0pt}[\height][0pt]{\usebox{\aebox}}}
\begin{document}

\begin{aligned}[t] \dfrac{20-5x^{2}}{x^{2}+x-6} &=\dfrac{5(4-x^{2})}{(x+3) (x-2)} && \textcolor{blue}{\text{Factor}} \\ &=\dfrac{5(2+x)(2-x)}{(x+3)(x-2)} && \textcolor{blue}{\text{Factor completely}} \\ &=\dfrac{5(2+x) \cdot \textcolor{red}{-1}(\colorbox{cyan!25!white}{x-2$})} {(x+3)(\colorbox{cyan!25!white}{$x-2$})} %% && \textcolor{blue}{\text{Notice opposites in$2-x$and$x-2$. Write$2-x$as$-1(x-2)$and simplify}} \\ && \aecomment{Notice opposites in$2-x$and$x-2$. Write$2-x$as$-1(x-2)and simplify} \\ &=-\dfrac{5(2+x)}{x+3} \end{aligned}

\end{document}


Now, I should caution that I've nulled out the depth of the comment. That means if you write something like:

\begin{aligned}[t] \dfrac{20-5x^{2}}{x^{2}+x-6} &=\dfrac{5(4-x^{2})}{(x+3) (x-2)} && \textcolor{blue}{\text{Factor}} \\ &=\dfrac{5(2+x)(2-x)}{(x+3)(x-2)} && \textcolor{blue}{\text{Factor completely}} \\ &=\dfrac{5(2+x) \cdot \textcolor{red}{-1}(\colorbox{cyan!25!white}{x-2$})} {(x+3)(\colorbox{cyan!25!white}{$x-2$})} %% && \textcolor{blue}{\text{Notice opposites in$2-x$and$x-2$. Write$2-x$as$-1(x-2)$and simplify}} \\ && \aecomment{Notice opposites in$2-x$and$x-2$. Write$2-x$as$-1(x-2)and simplify} \\ &=-\dfrac{5(2+x)}{x+3} && \textcolor{red}{\text{\bfseries Smashes into line above!!!}} \end{aligned}


I tend to use such comments sparingly. So such clashes are not a significant issue for me. But here you can see what happens if I don't null out the depth:

If you don't mind the extra space created in the equation by the long comment, then just remove the \raisebox portion of the details.

This crashing can be avoided by using \raisebox to actually raise the box by a specified amount. Here I redefine the \aecomment

\newbox\aebox
\newcommand\aecomment[2][0pt]{%%
\begin{lrbox}\aebox
\begin{minipage}[t]{2in}
\raggedright
\textcolor{blue}{#2}%%
\end{minipage}%%
\end{lrbox}%%
\raisebox{#1}[\height][0pt]{\usebox{\aebox}}}


Calling it as follows:

\begin{aligned}[t] \dfrac{20-5x^{2}}{x^{2}+x-6} &=\dfrac{5(4-x^{2})}{(x+3) (x-2)} && \textcolor{blue}{\text{Factor}} \\ &=\dfrac{5(2+x)(2-x)}{(x+3)(x-2)} && \textcolor{blue}{\text{Factor completely}} \\ &=\dfrac{5(2+x) \cdot \textcolor{red}{-1}(\colorbox{cyan!25!white}{x-2$})} {(x+3)(\colorbox{cyan!25!white}{$x-2$})} && \aecomment[2.5ex]{Notice opposites in$2-x$and$x-2$. Write$2-x$as$-1(x-2)and simplify} \\ &=-\dfrac{5(2+x)}{x+3} && \textcolor{red}{\text{\bfseries No crashing into line above!!!}} \end{aligned}


Resulting in no clash but also not effecting the spacing in the equation itself either.

• It is close but yes it smashes into the next comment area. If we could move notice somewhat. I see the next solution Oct 2 '18 at 19:19
• Can the raisebox help move the line starting with Notice up towards the top of the numerator fraction? Oct 2 '18 at 19:30
• @MathScholar I've just updated the answer to reflect exactly that issue. Oct 2 '18 at 19:31

A simple solution with the stackengine package:

\documentclass{article}
\usepackage{amsmath,xcolor,geometry}
\usepackage[usestackEOL]{stackengine}

\begin{document}

\begin{aligned}[t] \dfrac{20-5x^{2}}{x^{2}+x-6}&=\dfrac{5(4-x^{2})}{(x+3) (x-2)} && \textcolor{blue}{\text{Factor}} \\ &=\dfrac{5(2+x)(2-x)} {(x+3)(x-2)} && \textcolor{blue}{\text{Factor completely}} \\ &=\dfrac{5(2+x) \cdot \textcolor{red}{-1}(\colorbox{cyan!25!white}{x-2$})} {(x+3)(\colorbox{cyan!25!white}{$x-2$})} && \textcolor{blue}{\Centerstack[l]{Notice opposites in$2-x$and$x-2$. \\Write$2-x$as$-1(x-2)and simplify}} \\ &=-\dfrac{5(2+x)}{x+3} \end{aligned}

\end{document}