3

I want to center an equation inside a cell in the aligned environment from the amsmath package.

This is my MWE:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\boxed{\begin{aligned}
\mbox{Therefore, one plus one equals two.}\\
1+1=2
\end{aligned}}$
\end{document}

and it produces

enter image description here

To be clear, I want 1+1=2 to be centered.

2 Answers 2

4

I suggest you switch from an aligned to a gathered environment.

enter image description here

\documentclass{article}
\usepackage{amsmath} % for '\boxed' macro and 'gathered' env.
\begin{document}
$\boxed{\begin{gathered}
        \textnormal{Therefore, one plus one equals two.}\\
        1+1=2
        \end{gathered}}$
\end{document}
3
  • Thank you very much! May I ask why you use inline math mode instead of display math mode? Nov 27, 2023 at 21:32
  • 1
    @Pseudonym123 - The code you posted originally didn't contain any switch to math mode, and hence wasn't compilable since \boxed must occur in math mode. I just chose the simpler of the two available options. For sure, your code (and mine -- the only difference being in the use of aligned and gathered environments) works equally well in either math mode.
    – Mico
    Nov 27, 2023 at 22:27
  • 1
    Thanks for the clarification! Nov 27, 2023 at 22:41
4

I suggest you switch from an aligned to TeX primitive \halign.

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\boxed{\vbox{\halign{\hfil#\hfil\cr
Therefore, one plus one equals two.\cr
$1+1=2$\cr}}}

\end{document}

You must log in to answer this question.

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