3

I am using amsmath, and I want to be able to break a mathematical derivation into multiple align environments while maintaining their collective alignment. In particular, I would like to horizontally align an entire derivation as though it were one align environment for the purposes of visual flow, so that when the derivation continues in the next align, the eye can easily follow from where it left off, despite arbitrary explanatory text at any point in the middle.

As far as I'm aware, aligning align environments in this fashion is not directly possible. Is there a simple modification that can be made or a straightforward package that can be used to effectively "link" multiple align environments into one?

MWE

\documentclass{article}
\usepackage{amsmath}

\begin{document}

This alternate derivation of the quadratic formula proceeds by first multiplying the equation by $4a$, rearranging, and adding $b^2$ to both sides:
\begin{align}
    ax^2 + bx + c &= 0 \\
    4 a^2 x^2 + 4abx + 4ac &= 0 \\
    4 a^2 x^2 + 4abx &= -4ac \\
    4 a^2 x^2 + 4abx + b^2 &= b^2 - 4ac
\end{align}

Then, having completed the square on the left-hand-side, factor it, take the square root, and solve for $x$:
\begin{align}
    (2ax + b)^2 &= b^2 - 4ac \\
    2ax + b &= \pm \sqrt{b^2-4ac} \\
    2ax &= -b \pm \sqrt{b^2-4ac} \\
    x &= \frac{-b \pm \sqrt{b^2-4ac}}{2a}
\end{align}

\end{document}

Output

MWE and Desired Effect

David Carlisle
  • 757,742
Tim Parenti
  • 1,251

1 Answers1

0

You can use the tabbing environment. This way you set up the desired spacing and then you can reuse it so they align down the page.

So if I wanted, the spacing below:

\begin{tabbing} \hspace{2cm} \= \hspace{.5cm} \= \hspace{3cm} \= \kill
Your equations here separated by \> \> and math delimiters for the math \\
\(x\) \> \(=\) \> \(6x\)\\
....
\end{tabbing}

If I invoke this later, it will align with the previous tabbing. If you want to center the equations, add \hspace{xcm} \= where x is the desired cms to center the line.

Someone taught me this on one of my posts:

If you want numbering in the tabbing environment, use \tagthisline and insert this into your preamble:

% line numbering for tabbing                                                         
\newcommand{\tagthisaux}{%                                                           
  \refstepcounter{equation}%                                                         
  (\theequation)%                                                                    
}
\newcommand{\tagthisline}{\`\tagthisaux}

Your code with exact spacing:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

This alternate derivation of the quadratic formula proceeds by first multiplying
the equation by $4a$, rearranging, and adding $b^2$ to both sides:
\begin{tabbing} \hspace{3cm} \= \hspace{3cm} \= \hspace{.5cm} \= \hspace{3cm} \=
\kill
\> \(ax^2 + bx + c\) \> \(=\) \> \(0\) \\
\> \(4 a^2 x^2 + 4abx + 4ac\) \> \(=\) \> \(0\) \\
\> \(4 a^2 x^2 + 4abx \) \> \(=\) \> \(-4ac\) \\
\> \(4 a^2 x^2 + 4abx + b^2\) \> \(=\) \> \(b^2 - 4ac\)
\end{tabbing}
Then, having completed the square on the left-hand-side, factor it, take the
square root, and solve for $x$:
\begin{tabbing} \hspace{4.5cm} \= \hspace{1.5cm} \= \hspace{.5cm} \=
\hspace{1cm} \= \kill
\> \((2ax + b)^2\) \> \(=\) \> \(b^2 - 4ac\) \\
\> \(2ax + b\) \> \(=\) \> \(\pm \sqrt{b^2-4ac}\) \\
\> \(2ax\) \> \(=\) \> \(-b \pm \sqrt{b^2-4ac}\) \\
\> \(x\) \> \(=\) \> \(\frac{-b \pm \sqrt{b^2-4ac}}{2a}\)
\end{tabbing}

\end{document}

As you can see you just need the first two to add up to the same value which is 6 then they align at the =

enter image description here

Code with \tagthisline command:

enter image description here

If you want to increase the space between the lines, you can add [.3cm] after each \\. Also, you can use \displaystyle in the delimiters to get the displaymath appearance.

Code with \displaysytle and [.3cm] after \\

enter image description here

David Carlisle
  • 757,742
dustin
  • 18,617
  • 23
  • 99
  • 204
  • Breaking the equations into multiple equations to tabularize them like this seems like a bit of an abuse of the tabbing environment, something one Should Not Do. Since I'm curious, though, is there a way to right-align a tab stop within tabbing to achieve proper alignment of the left-hand-side? – Tim Parenti Jun 21 '13 at 15:52
  • No need to delete the comments; better to preserve the history. But adding \` in front seems only to right-align the right-hand-side against the margin of the page, which is worse. – Tim Parenti Jun 21 '13 at 16:24
  • 1
    @TimParenti I cant figure anything fruitful out but I bet some others could. You may need to ask a separate question on right aligning inside the tabbing environment. – dustin Jun 21 '13 at 17:04
  • just one more quibble -- the space between the equal sign and what follows it is uniformly too large. (the same space should really be used to the left of the equal sign, though that's hardly relevant with the left alignment. however, that space shouldn't be smaller than the space after the equal sign.) – barbara beeton Jun 21 '13 at 18:06
  • @barbarabeeton I wrote in a comment to Tim's question post that could be adjusted. I just throw it together to show it works as he would like. – dustin Jun 21 '13 at 18:08
  • @dustin Except that it doesn't work as I would like... while I can see the utility of tabbing in other contexts, there's a bit too much manual adjustment required for this solution to be considered "simple", I think. – Tim Parenti Jun 21 '13 at 18:29
  • @TimParenti once you familiar with it, it will be simple. You should try asking another question on right aligning the the 2nd tabbing environment. I would guess Werner, egreg, Qrrbrbirlbel, David Carlisle, Marco Daniel, baraba beeton, and there are many more that may have a handle on doing such adjustment. – dustin Jun 21 '13 at 18:39
  • 2
    @dustin -- no chance that i would recommend adjusting a group of equations aligned with a tabular mechanism. yes, i could do it, but this problem is one of the reasons amsmath was created, and that handles it more reliably. – barbara beeton Jun 21 '13 at 18:59