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} ```

Siuslaw Math
  • 641
  • 3
  • 8

1 Answers1

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}

tobiasBora
  • 8,684
  • thanks so much for providing a solution I never would have found on my own! Question marked "solved" – Siuslaw Math Apr 03 '23 at 19:52
  • 1
    @SiuslawMath By the way, you might prefer to simply use \begin{align} instead of nesting equation and aligned. – tobiasBora Apr 03 '23 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. – Siuslaw Math Apr 03 '23 at 20:07
  • @toabiasBora Sorry. I initially didn't see that you had revised mwe code in the OP. Thanks for doing that! – Siuslaw Math Apr 03 '23 at 20:09
  • 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 03 '23 at 20:48
  • @toabiasBora Yes, I now see align vs aligned. What is causing the enumeration of the solution steps on the right side? Thank you! – Siuslaw Math Apr 03 '23 at 21:14
  • 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 03 '23 at 21:29
  • ah, yes, forget about {align*}. For my high school algebra classes, usually I use enumeration to number each problem in the problem set. But your point is well taken! – Siuslaw Math Apr 03 '23 at 21:45