0

Greetings LaTeX Masters!

In the code below, I'm trying to align the solution steps on the equal sign. The alignment works until I get to the final step where I draw a box around the solution. This line of code doesn't draw the box:

\boxed{x&=2} and crashes the compiler.

Without the &, the solution box doesn't align.

[![Mis-aligned solution box][1]][1]

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

Trapezoids: Median line formula\\

%\setcounter{equation}{2}
\begin{equation}
\setlength{\jot}{8pt}
    \begin{aligned}
    Median &= \dfrac{1}{2}(top + bottom)\\
    3x+1&=\dfrac{(2x+1)+(2x+5)}{2}\\
    2\cdot (3x+1)&=\Biggl(\dfrac{(2x+1)+(2x+5)}{2}\Biggr) \cdot \dfrac{2}{1}\\
    6x+2&=4x+6\\
    6x&=4x+4\\
    2x&=4\\
  \boxed{x=2}
    \end{aligned}
\end{equation}

\end{document} ```


  [1]: https://i.stack.imgur.com/eKBHo.png
2
  • 2
    not specific to boxed you can not use {...} around a & in any tex alignment Apr 3, 2023 at 19:45
  • @David Carlisle Thank you! So can you please suggest a way to get the solution box to align on the equal sign? Apr 3, 2023 at 19:47

1 Answer 1

3

See How to make a box around an equation in align-environment

You can't use directly stuff like \yourcommand{a & b} or LaTeX will think that the & symbol might be use for something else inside the \yourcommand macro. For instance, \yourcommand could be a shortcut to create an array.

You can use \Aboxed{…} from mathtools.

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

Trapezoids: Median line formula\\

\begin{align}
  Median &= \dfrac{1}{2}(top + bottom)\\
  3x+1&=\dfrac{(2x+1)+(2x+5)}{2}\\
  2\cdot (3x+1)&=\Biggl(\dfrac{(2x+1)+(2x+5)}{2}\Biggr) \cdot \dfrac{2}{1}\\
  6x+2&=4x+6\\
  6x&=4x+4\\
  2x&=4\\
  \Aboxed{x&=2}  
\end{align}

\end{document}
8
  • thanks so much for providing a solution I never would have found on my own! Question marked "solved" Apr 3, 2023 at 19:52
  • 1
    @SiuslawMath By the way, you might prefer to simply use \begin{align} instead of nesting equation and aligned.
    – tobiasBora
    Apr 3, 2023 at 20:00
  • So I removed \begin{equation} and ```\end{equation} as suggested (assuming I followed instructions correctly). But now I get a "not in math mode" error. Note: The mwe code has been revised to reflect this change. Apr 3, 2023 at 20:07
  • 1
    @SiuslawMath you also need to remove the ed in the aligned (see my edit, in my first answer I only fixed the indentation).
    – tobiasBora
    Apr 3, 2023 at 20:48
  • 1
    @SiuslawMath if you don't want the enumeration on the right, you can use the star version \begin{align*}…\end{align*}. Enumeration is useful to refer to the equations later.
    – tobiasBora
    Apr 3, 2023 at 21:29

You must log in to answer this question.

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