Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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!

share|improve this question
2  
You don't seem to have closed your \fbox! –  Joseph Wright Aug 11 '11 at 20:43
1  
Few issues: You are using inline math with the $$ and yet trying to insert a newline \\. Also the underscores will need to be escaped as in a\_caption. –  Peter Grill Aug 11 '11 at 20:49
    
Only in the caption, in the label it doesn't hurt. –  Herbert Aug 11 '11 at 21:07
    
@Herbert: I get Missing $ inserted. if I don't escape the underscores. –  Peter Grill Aug 11 '11 at 21:08
    
yes, for the caption, but not for the label. –  Herbert Aug 11 '11 at 21:12
add comment

2 Answers

up vote 4 down vote accepted
  • 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.

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.