3

I have the code

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath, amssymb, amsthm}

\begin{document}
\begin{alignat*}{3}
    2^0 &= 1 \pmod{21}, &\qquad 2^4 &\qquad &= 16 \pmod{21},\\
    2^1 &= 2 \pmod{21}, &\qquad 2^5 &= 32   &= 11 \pmod{21},\\
    2^2 &= 4 \pmod{21}, &\qquad 2^6 &= 64   &= 1  \pmod{21}.\\
    2^3 &= 8 \pmod{21}, &\qquad     &\qquad &\qquad
\end{alignat*}
\end{document}

but it's producing this:

Bad LaTeX formatting

How do I get those equals on the right to be lined up?

Pro Q
  • 287

2 Answers2

4

An alignat solution, even if I would use an ordinary tabular or array, see here.

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath, amssymb, amsthm}

\begin{document}

\begin{alignat*}{4}
2^0 &= 1 \pmod{21},&\qquad  2^4 & &  & = {} &  16    &  \pmod{21},\\
2^1 &= 2 \pmod{21}, &  2^5 &= 32 & & =   & 11  &   \pmod{21},\\
 2^2 &= 4 \pmod{21}, &  2^6 &= 64 & & =  & 1  &  \pmod{21}.\\
2^3 &= 8 \pmod{21},
\end{alignat*}

\end{document}

enter image description here

Bernard
  • 271,350
CarLaTeX
  • 62,716
2

Here, I use a \tabularCenterstack, which has column-alignment features similar to tabular, while providing math spacing features across tabs, similar to align.

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath, amssymb, amsthm, tabstackengine}
\TABstackMath
\begin{document}
\TABbinary
\setstackgap{L}{1.2\baselineskip}
\setstacktabulargap{0pt}
\[\tabularCenterstack{rlrlcrl}{
    2^0 &= 1 \pmod{21}, &\qquad 2^4 &       &=& 16 &\pmod{21},\\
    2^1 &= 2 \pmod{21}, &\qquad 2^5 &= 32   &=& 11 &\pmod{21},\\
    2^2 &= 4 \pmod{21}, &\qquad 2^6 &= 64   &=& 1  &\pmod{21}.\\
    2^3 &= 8 \pmod{21}, &           &       & &    &
}
\]
\end{document}

enter image description here