To align several equations in Latex, I write a code like this:
\begin{alignat*}{7}
d &= \frac{1}{1 + 0.2316419x} & \quad & a_1 &= 0.31938153 & \quad & a_2 &= -0.356563782 \\
a_3 &= 1.781477937 & \quad & a_4 &= -1.821255978 & \quad & a_5 &= 1.330274429
\end{alignat*}
And I got something like this.
I don't understand why there is a space between a_1 and '='. Could you please tell me how to eliminate that space ? Thank you for your time.
The eqnarray environment lets you align equations so that, for example, all of the equals signs "=" line up. To do this, put ampersand "&" signs around the text you want LaTeX to align, e.g. Each equation can be labelled separately, just put the label command after the relevant equation.
Instead of centering you may consider to align all equations at the equal sign and center the whole multiline environment. For this, use the align or align* environment, see the amsmath user's guide (or type texdoc amsldoc at the command prompt). In any case, use amsmath .
Displaying long equations For equations longer than a line use the multline environment. Insert a double backslash to set a point for the equation to be broken. The first part will be aligned to the left and the second part will be displayed in the next line and aligned to the right.
The flalign (flush align) environment provided by AMS-LaTeX allows one to align multi-line equations. Lines are separated with a double backslash (\\) and ampersands (&) are used for alignment.
You can use the following approach:
\begin{alignat*}{3}
& d = \frac{1}{1 + 0.2316419x} \quad && a_1 = 0.31938153 \quad && a_2 = -0.356563782 \\
& a_3 = 1.781477937 \quad && a_4 = -1.821255978 \quad && a_5 = 1.330274429
\end{alignat*}
that results into:
Another question about alginat has an answer that explains what happens ( https://tex.stackexchange.com/questions/49014/aligning-equations-with-text-with-alignat).
The idea is that alginat uses an rl alignment structure. This means that the first column is right aligned and the second is left aligned. This is what happened with you, as "a_1" is left aligned and "= 0.31938153 " is right aligned. Because of the negative sign in the line below this creates unwanted space.
To deal with this, as xiawi pointed out, you simply add another column. Alignat doesn't add extra space, so this will not mess up your spacing, and make both columns left aligned. However, you could also move the equality sign to the previous column if you want to keep the space to emphasise the sign difference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With