How can I make this in LaTeX? So that both the words and the equality symbols are aligned, exactly like in the image
3 Answers
You can use the aligned environment:
\documentclass{article} \usepackage{amsmath} \begin{document} $\begin{aligned} &\text{If } & a+x&= a\\ &\text{then } & (-a)+(a+x)&= (-a)+a=0;\\ &\text{hence } & ((-a)+a)+x&=0;\\ &\text{hence } & 0+x&=0;\\ &\text{hence } & x&= 0. \end{aligned}$ \end{document} - Does
alignedadd anything overalign*in this case?Teepeemm– Teepeemm2024-10-10 22:03:05 +00:00Commented Oct 10, 2024 at 22:03 - It gives the same thing, or almost. By default,
align*centers the equation, whilealignedtreats it as "text". So since the set of equations is ragged left, I chosealigned.stargazer45– stargazer452024-10-10 22:07:52 +00:00Commented Oct 10, 2024 at 22:07
You can use aligned or alignat, depending on how you want to control the spacing:
\documentclass{article} \usepackage{amsmath} \begin{document} \begin{alignat*}{2} & \mathrm{If} & a + x &= a, \\ & \mathrm{then} & (-a)+(a+x)&= (-a)+a=0;\\ & \mathrm{hence}\quad &((-a)+a)+x &= 0; \\ & \mathrm{hence} & 0 + x &= 0; \\ & \mathrm{hence} & x &= 0. \end{alignat*} \begin{equation*} \begin{aligned} &\mathrm{If} & a+x&= a\\ &\mathrm{then} & (-a)+(a+x)&= (-a)+a=0;\\ &\mathrm{hence} & ((-a)+a)+x&=0;\\ &\mathrm{hence} & 0+x&=0;\\ &\mathrm{hence} & x&= 0. \end{aligned} \end{equation*} \end{document} I know the current answers already answer this question. But here it goes another option. This using an array environment.
\begin{equation*} \begin{array}{lrcl} \text{If} & a+x & = & a,\\ \text{then} & (-a)+(a+x) & = & (-a)+a=0;\\ \text{hence} & ((-a)+a)+x & = & 0;\\ \text{hence} & 0+x & = & 0;\\ \text{hence} & x & = & 0. \end{array} \end{equation*} Make sure to replace \text with \rm in case that you do not want the text to match your current font style and want Roman for some reason. Hope it helps!
Edit: As suggested below, one should note that the lines are spaced more closely than in other environments. To control this (if you want to) you can add the desired line space after each linebreak, e.g. \\[1 ex]. My impression is that the array environment gives you more freedom, but this also comes with having to develop the skills to tailor it to suit your needs.
- 1Note
\rmis not defined by default in latex, and this produces unequal spacing around the = compare the two = on the second lineDavid Carlisle– David Carlisle2024-10-11 00:58:17 +00:00Commented Oct 11, 2024 at 0:58 - You should also mention (as a caveat for readers) that in an
arrayenvironment, the material is typeset in text-style math mode instead of in display-style math mode and that the lines are spaced more closely than is the case in a usual multi-row math environment (such asalign*).Mico– Mico2024-10-11 07:19:14 +00:00Commented Oct 11, 2024 at 7:19


