[Tex/LaTex] Questions about \fbox

boxesframed

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!

Best Answer

  • 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.