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 want to place an \fbox inside of some \part, \chapter, and \section commands. Instead, I get this message:

Use of \@chapter doesn't match its definition.

Update:

\documentclass{article}
\usepackage{xcolor}
\begin{document}
    \section{\fbox{hi}}
\end{document}
share|improve this question
    
Using \chapter{A \fbox{test}} or \section{A \fbox{test}} works without a problem, even if you include \tableofcontents. Would you be able to provide an MWE that duplicates the problem? –  Werner Nov 12 '11 at 7:58
    
While making the MWE, I discovered it only has problems when I add \usepackage{xcolor} to my document. –  Village Nov 12 '11 at 8:04

1 Answer 1

up vote 9 down vote accepted

Protecting your \fbox in a section command (since it is fragile) allows for it to be used without problem:

enter image description here

\documentclass{article}
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\begin{document}
\tableofcontents
\section{\protect\fbox{hi}}
\section{\colorbox{green!25}{there}}
\end{document}

Alternatively, the etoolbox package provides \robustify{<cmd>} which can make <cmd> non-fragile:

\documentclass{article}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\robustify{\fbox}% Make \fbox non-fragile
\begin{document}
\tableofcontents
\section{\fbox{hi}}
\section{\colorbox{green!25}{there}}
\end{document}

Similar functionality is provided by makerobust. Also see the discussion What is the difference between Fragile and Robust commands?

share|improve this answer
    
Good, that has done it! I find that introduced a new problem. The \fbox{}'s are inside \footnote{}'s which are in the section titles using \usepackage[stable]{footmisc}. The footnotes now run too long on the page (covering up the page number). Is that likely a side-effect of using \protect? –  Village Nov 12 '11 at 8:13
1  
It shouldn't be. Since this may be related to footmisc, post a new question that shows this in an MWE. –  Werner Nov 12 '11 at 8:20

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.