LaTeX How can I put multiple line equations inside a box in Latex?

  • Thread starter Thread starter kdv
  • Start date Start date
  • Tags Tags
    Box Latex
AI Thread Summary
The discussion revolves around the challenge of placing multi-line equations inside a box using LaTeX. The original poster successfully used the \boxed command for single-line equations but encountered compilation errors when attempting to apply it to multi-line equations within an eqnarray environment. A solution was provided, demonstrating the use of the \begin{gathered} and \begin{split} environments to achieve the desired formatting. The solution also included adjusting the box padding with \addtolength{\fboxsep} for better visual appeal. Additionally, it was noted that including the necessary packages, such as \usepackage{amsmath} and \usepackage{amssymb}, in the LaTeX preamble is essential for proper compilation. The exchange highlights effective methods for formatting complex equations in LaTeX, particularly for users seeking to enhance their document presentation.
kdv
Messages
345
Reaction score
5
I am not sure if this is the right place to post a Latex question. If not, tell me where I should go.

I would like to put equations inside a box. Now, I have found two ways to do this butthey work only for single line equations. The best method is to simply put the equations between boxed braces, i.e. \boxed{ equation}

this works if I am in an equation array i.e.

\begin{equation} \boxed{equation} \end{equation}

I have tried the same thing in an eqnarray but I get compilations errors. I would like to have equations spanning several lines which would be inside a box.

Anybody can help?

Thanks
 
Physics news on Phys.org
kdv said:
I am not sure if this is the right place to post a Latex question. If not, tell me where I should go.

I would like to put equations inside a box. Now, I have found two ways to do this butthey work only for single line equations. The best method is to simply put the equations between boxed braces, i.e. \boxed{ equation}

this works if I am in an equation array i.e.

\begin{equation} \boxed{equation} \end{equation}

I have tried the same thing in an eqnarray but I get compilations errors. I would like to have equations spanning several lines which would be inside a box.

Anybody can help?

Thanks

There are instructions in the https://www.physicsforums.com/showthread.php?t=8997" here at the forum. I haven't read the entire thing. There are over 700 posts.
 
Last edited by a moderator:
kdv said:
I am not sure if this is the right place to post a Latex question. If not, tell me where I should go.

I would like to put equations inside a box. Now, I have found two ways to do this butthey work only for single line equations. The best method is to simply put the equations between boxed braces, i.e. \boxed{ equation}

this works if I am in an equation array i.e.

\begin{equation} \boxed{equation} \end{equation}

I have tried the same thing in an eqnarray but I get compilations errors. I would like to have equations spanning several lines which would be inside a box.

Anybody can help?

Thanks

I found a way but I am not sure if it will work on the forums here, so here's the trick:
<br /> \begin{equation*}<br /> \addtolength{\fboxsep}{5pt}<br /> \boxed{<br /> \begin{gathered}<br /> \Pi_{i=1}^m \int d^4x_i \, e^{-i (k \cdot x)_i} ~\Pi_{j=1}^n \int d^4y_j \, e^{+ i (p \cdot y)_j} \\<br /> &lt;0| T\{ \phi(x_1) \ldots \phi(x_m) \phi(y_1) \ldots \phi(y_n) \} |0&gt;<br /> \\ = \biggl( \Pi_{i=1}^m \frac{i \sqrt{Z}}{k_i^2 - m^2} \biggr) \biggl(\Pi_{j=1}^n \frac{i \sqrt{Z}}{p_j^2 - m^2} \biggr) ~&lt;\vec{p}_1 \ldots \vec{p_n}|i T| \vec{k_1} \ldots \vec{k_m}&gt;<br /> \end{gathered}<br /> }<br /> \end{equation*}<br />

It worked!

(For anybody interested, left click on the equation to see the source code)
 
Thanks a lot for this tip kdv I'd been wondering how to get boxes around multiline equations.

Also, for alignment you can use the 'split' environment rather than 'gathered'.

<br /> \begin{equation*}<br /> \addtolength{\fboxsep}{10pt}<br /> \boxed{<br /> \begin{split}<br /> \int \frac{d^D P}{(2\pi)^D} \frac{{\cal P}_n(P)}<br /> {P^{2\alpha}(P-Q)^{2\beta}} =<br /> &amp;\frac{1}{(4\pi)^2}(Q^2)^{D/2-\alpha-\beta}\sum_{\sigma \ge 0}^{[n/2]}<br /> G(\alpha,\beta,n,\sigma) \cdot \\<br /> &amp;\cdot Q^{2\sigma} \left\{ \frac{1}{\sigma !}<br /> \left( \frac {\Box} {4} \right) ^\sigma {\cal P}_n(P)\right\}_{P=Q}<br /> \end{split}<br /> }<br /> \end{equation*}<br />

For anybody compiling this remember to include \usepackage{amsmath} in your preamble and for this particular example also \usepackage{amssymb} for the D'Alembertian.

Thanks again.
 
kdv, thanks for posting your answer after finding it. Google funneled me here, and your post has helped me out.
 
Back
Top