0

I am trying to align these equations together but I can't figure out how to do that without centering absolutely everything.

below is what I currently have

\begin{addmargin}\[1em\]{1em}

    \textbf{(a)} $A \cup B$\\
    $$A \cup B = \{1,3,4,5,6,7,8,9\}$$
    
    \textbf{(b)} $A \cap B$\\
    $$A \cap B = \{4,8\}$$
    
    \textbf{(b)} $A - B$\\
    $$A - B = \{3,7,1,9\}$$

\end{addmargin}

when this is compiled it shows this enter image description here As you can see the equations are centered but I want them to align on the equal sign. Does anybody know a way to do this?

1
  • 1
    Have a look at this answer. In order to align adjacent lines, all lines must be included within a single environment. Your use of \\ before a display (the function of $$) will produce incorrect vertical spacing. Commented Sep 5 at 1:08

2 Answers 2

0

Here is one hacky way to do it by using a table. I used tabularray package to easily control the space between the columns.

\documentclass[preview]{standalone}

\usepackage{array}
\usepackage{tabularray}


\begin{document}
    $\begin{tblr}{width=0.7\textwidth, colspec={X[2]rcl}, colsep=.1em}
        \textbf{(a)}\, A \cup B & & & \\
            & A \cup B &=&\{1,3,4,5,6,7,8,9\}\\
        \textbf{(b)}\, A \cap B & & & \\
            & A \cap B &=&  \{4,8\}\\
        \textbf{(c)}\, A - B & & & \\
            & A - B &=&\{3,7,1,9\}\\
    \end{tblr}$
\end{document}

enter image description here

1
  • you insert wrong image ... equations are not aligned at equal signs.
    – Zarko
    Commented Sep 5 at 11:11
0

You do want align.

\documentclass{article}
\usepackage{amsmath,mathtools}

\begin{document}

\begin{align*}
\shortintertext{\textbf{(a)} $A \cup B$}
  A \cup B &= \{1,3,4,5,6,7,8,9\}
\shortintertext{\textbf{(b)} $A \cap B$}
  A \cap B &= \{4,8\}
\shortintertext{\textbf{(c)} $A - B$}
  A - B &= \{3,7,1,9\}
\end{align*}

\end{document}

output

Avoid using $$ inside a LaTeX document environment: it's unsupported and doesn't behave correctly with respect to document class options. See Why is \[ ... \] preferable to $$ ... $$?

In any case, \\ should not be used before a math display (and generally not to end lines except in specific environments).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .