How to Put a Box Around a Numbered Equation?

  • LaTeX
  • Thread starter NoobixCube
  • Start date
  • Tags
    Latex
In summary, to put a box around a numbered equation, you can use the "boxed" command from the amsmath package or define a new command using the "fbox" and "addtolength" commands. This allows you to either box just the equation or the entire line, including the equation number. Be careful with spacing when defining the new command to ensure proper alignment of equation numbers.
  • #1
NoobixCube
155
0
How do you put a box around a numbered equation?
 
Physics news on Phys.org
  • #2
Hi NoobixCube,

NoobixCube said:
How do you put a box around a numbered equation?

Were you wanting the box around just the equation itself (but not the equation number)? I do that quite often with the boxed command from the amsmath package:

Code:
\documentclass{article}

\usepackage{amsmath}

\begin{document}

some text

\begin{equation}
\boxed{
x^2+y^2 = z^2
}
\end{equation}

more text

\end{document}


If you want the entire line to be boxed (including the equation number), you can nest boxes, something like:

\[
\fbox{
\addtolength{\linewidth}{-2\fboxsep}%
\addtolength{\linewidth}{-2\fboxrule}%
\begin{minipage}{\linewidth}
\begin{equation}
x^2+y^2=z^2
\end{equation}
\end{minipage}
}
\]

Of course you would not want to type that in for every equation, so you could define a new command once in the preamble, so that your document looks like:

Code:
\documentclass{article}


\newcommand{\boxeqn}[1]{
\[
\fbox{
\addtolength{\linewidth}{-2\fboxsep}%
\addtolength{\linewidth}{-2\fboxrule}%
\begin{minipage}{\linewidth}
\begin{equation}
#1
\end{equation}
\end{minipage}
}
\]
}

\begin{document}

some text

\begin{equation}
x^2 + y^2 = z^2
\end{equation}

more text

\boxeqn{
a^2 + b^2 = c^2
}

more text

\boxeqn{
\oint \vec B\cdot d\vec A =0
}

\end{document}


In the above definition, the lines with "addtolength" accounts for the separation between the box and its contents, and for the width of the line around the box. (and these lengths are controlled by fboxsep and fboxrule.) With that taken into account, the equation numbers for the boxed and unboxed equations are all lined up. (The comment symbols % keep spaces from being added at the wrong spot.)



EDIT: If you modify the definition (so it is on fewer lines) remember that spaces are needed at the appropriate places. So for example if you tried to combine the third and fourth line like this:

\newcommand{\boxeqn}[1]{
\[
\fbox{\addtolength{\linewidth}{-2\fboxsep}%%%%<---CHANGING THIS LINE
\addtolength{\linewidth}{-2\fboxrule}%
\begin{minipage}{\linewidth}
\begin{equation}
#1
\end{equation}
\end{minipage}
}
\]
}

so as to put \fbox and the first \addto length on the same line, the equation numbers won't line up any more; you would need to insert a space between those two:

\newcommand{\boxeqn}[1]{
\[
\fbox{ \addtolength{\linewidth}{-2\fboxsep}%
\addtolength{\linewidth}{-2\fboxrule}%
\begin{minipage}{\linewidth}
\begin{equation}
#1
\end{equation}
\end{minipage}
}
\]
}
 
Last edited:
  • #3
That helped loads! Thanks man!
 
  • #4
Sure, glad to help!
 

1. What is LATEX and how is it used in equations?

LATEX is a typesetting system that is commonly used in scientific and mathematical fields to write and format equations. It allows for precise and professional-looking equations to be created and is often used in research papers and publications.

2. What are Q-boxes in LATEX equations?

Q-boxes in LATEX equations are used to enclose and highlight a specific part of an equation. They are similar to regular brackets or parentheses, but are specifically designed for use in mathematical equations.

3. How do you create a Q-box in a LATEX equation?

To create a Q-box in a LATEX equation, you can use the command "\boxed{ }", which will create a box around the contents within the curly braces. You can also use the command "\boxed{ }_{ }" to add a subscript below the box.

4. Can you change the size or color of a Q-box in a LATEX equation?

Yes, you can change the size and color of a Q-box in a LATEX equation by using additional commands within the curly braces. For example, "\color{red}\boxed{ }" will create a red box, and "\Huge\boxed{ }" will create a larger box.

5. Are Q-boxes necessary in LATEX equations?

No, Q-boxes are not necessary in LATEX equations, but they can be useful for emphasizing certain parts of an equation or for organizing complex equations. It is ultimately up to the preference of the writer or the guidelines of the publication.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
896
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
779
Replies
11
Views
431
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
964
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
Back
Top