1

I would like to put a text and a math formula inside a \fbox, but I got an error:ERROR: LaTeX Error: Something's wrong--perhaps a missing \item. Also the\\ did not work, so the text and the formula are still in one line.

\begin{figure}[htbp]
\centering
\fbox{%
  text\\
  $\begin{cases}
    abcdefghijklmn\\
    cdefg
   \end{cases}$
\caption{a_caption}
\label{a_label}
\end{figure}

Another question is that it seems that the width of the frame is up to the width of what I put inside fbox, what to do if I want the width to be the width of the page?

Could anyone help? Thank you very much!

David Carlisle
  • 757,742
SoftTimur
  • 19,767

2 Answers2

4

you have to use a parbox if you want a linebreak inside fbox. E.g. with package varwidth:

\fbox{\varwidth{\linewidth}%
      
text\\
      
$\begin{cases}
        
   abcdefghijklmn\\
        
   cdefg
       
 \end{cases}$\endvarwidth}

enter image description here

4
  • Regarding \fbox, as Joseph said: there's a closing brace missing, determining the end of the argument.

  • For the whole text width you could use the framed package and its environment with the same name, such as

    \usepackage{framed}
    ...
    \begin{figure}[htbp]
    \begin{framed}
      \centering
      text\\
      $\begin{cases}
        abcdefghijklmn\\
        cdefg
       \end{cases}$
    \end{framed}
    \caption{a caption}
    \label{a_label}
    \end{figure}
    
  • Another option is the improved version mdframed.

  • For framing math environments, there's the \boxed command of amsmath.

David Carlisle
  • 757,742
Stefan Kottwitz
  • 231,401