[Tex/LaTex] Inline Boxed Equation

boxesequationsmath-mode

I'm having trouble producing a boxed equation in the same line as some other formulae. For example: $$ \frac{2}{4} =\[\boxed{ \frac{1}{2} }\] $$

I'd like to be able to show some calculations, followed by a boxed final answer. Any ideas?

Best Answer

The standard LaTeX command for boxing something is \fbox. Its argument is in text mode; to switch to display format mathematics you need to issue

\fbox{$\displaystyle  ... $}

Thus your example becomes

\documentclass{article}

\begin{document}

\[ \frac{2}{4} =\fbox{$\displaystyle \frac{1}{2}$} \]

\end{document}

producing

Sample output

If you are using amsmath then its \boxed command (thanks daleif for the link) already takes care of switching to maths and display style, so you just write the code for the math object directly between the braces {...}

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\[ \frac{2}{4} = \boxed{\frac{1}{2}} \]

\end{document}

In other words in the argument to \boxed you do not need math mode switching commands such as \[..\].

Related Question