4

I have the following code:

\framebox{
  \begin{align*}
    Something here
  \end{align*}
}

which gives the following errors:

  1. Missing \endgroup inserted
  2. Missing } inserted
  3. LaTeX Error: \begin{document} ended by \end{align*}
  4. Missing $ inserted
  5. Display math should end with $$
  6. Extra \endgroup
  7. Too many }s

I'm new to Latex and don't understand why this is happening. Is this a Latex bug? How can I put an equation inside a box?

2
  • Another alternative to the ones in the existing answer: empheq.
    – E.P.
    Aug 11, 2017 at 9:47
  • 1
    if only a simple box is wanted, amsmath has \boxed{ \begin{aligned} ... \end{aligned} }. must be used in math mode. Aug 11, 2017 at 13:47

4 Answers 4

6

Not a bug, user error. \framebox is like \mbox and is a single line (horizontal mode) construct, align is a display construct that needs to be in vertical mode. There are several packages for boxed vertical material: mdframed and tcolorbox for example, or simply use

\fbox{\parbox{5cm}{\begin{align}....\end{align}}}
1

OK so here is an example : firstly use package \usepackage{amsmath,mathtools}

\begin{align}
\Aboxed{Nu_\text{m}        &= \frac{\alpha_m \, L}{\lambda}    \text{ \quad .}} \\ 
\Aboxed{Nu_\text{m}        &= \frac{\alpha_m \, L}{\lambda}    \text{ \quad .}}
\end{align}

remove * and put \Aboxed .

Output:

enter image description here

here is my full code:

\documentclass[
    german,
    paper=a4,
    ]{scrbook}              %KOMA-
\usepackage[latin1]{inputenc}
\usepackage[ngerman]{babel} 

\usepackage[babel,german=guillemets]{csquotes}
\usepackage[T1]{fontenc}    
\usepackage{amsmath,mathtools}

\begin{document}

\begin{align}
\Aboxed{Nu_\text{m}        &= \frac{\alpha_m \, L}{\lambda}    \text{ \quad .}} \\ 
\Aboxed{Nu_\text{m}        &= \frac{\alpha_m \, L}{\lambda}    \text{ \quad .}}
\end{align}

\end{document}
4
  • I think we don't have to define Aboxed . Aug 11, 2017 at 8:15
  • \Aboxed is defined by mathtools Aug 11, 2017 at 8:22
  • Sir, I respect you but my code is perfectly working. we can use package instead defining Aboxed Aug 11, 2017 at 8:22
  • 1
    My comment was before you had posted code, your edit showed where it was defined, in mathtools, which you had not mentioned in the original answer:-) Aug 11, 2017 at 8:23
1

I guess you want to box the equations, but this cannot be done that way, because \framebox doesn't support line breaks (directly).

You can avoid having to guess the width of the box by building the alignment beforehand.

\documentclass{article}
\usepackage{amsmath}

\usepackage{lipsum}% only for the example

\newsavebox{\boxedalignbox}
\newenvironment{boxedalign*}
  {\begin{equation*}\begin{lrbox}{\boxedalignbox}$\begin{aligned}}
  {\end{aligned}$\end{lrbox}\fbox{\usebox{\boxedalignbox}}\end{equation*}}

\begin{document}

\lipsum*[2]
\begin{boxedalign*}
a &= b(x+y)\\
  &= bx+by
\end{boxedalign*}
\lipsum[3]

\end{document}

enter image description here

2
  • why bother with this? amsmath has \boxed, into which an aligned environment fits admirably. Aug 11, 2017 at 13:27
  • @barbarabeeton Instead of \fbox one might want some different ornamentation.
    – egreg
    Aug 11, 2017 at 13:33
1

It is very easy to have any custom box for any equation environment with empheq. Needless to loadamsmath, as it loadsmathtools, which loads amsmath.

\documentclass{article}
\usepackage{empheq}
\usepackage[svgnames]{xcolor}

\newcommand\mybox[2][black]{\fboxrule=1pt\fboxsep=1.2ex\fcolorbox{#1}{white}{\enspace#2\enspace}}

\begin{document}

\begin{empheq}[box={\mybox[IndianRed]}]{align}
    (x + y)^3 & =x^3 + 3x^2y + 3xy^2 + y^3t\\%
    x^3 + y^3 & = (x + y)(x^2-xy + y^2)
\end{empheq}

\end{document} 

enter image description here

You must log in to answer this question.

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