Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Latex alignat syntax

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. What I got

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.

like image 838
ctnguyen Avatar asked Jun 11 '20 17:06

ctnguyen


People also ask

How do I align multiple equal signs in LaTeX?

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.

How do you center align an equation in LaTeX?

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 .

How do you write long equations in LaTeX?

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.

How do I use Flalign in LaTeX?

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.


2 Answers

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:

enter image description here

like image 87
xiawi Avatar answered Oct 19 '22 19:10

xiawi


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.

like image 2
Cath Avatar answered Oct 19 '22 19:10

Cath