6

I try to run this:

   \documentclass{article}
    \usepackage{amsmath}
    \renewcommand\thesection{\arabic{section}.}
    \makeatletter
    \renewcommand{\section}{
        \@startsection
            {section}{1}{0mm}
        {\baselineskip}%
        {\baselineskip} 
        {\fontsize{14}{14}\centering\bfseries\MakeUppercase}        
       }%
       \makeatother 
    \begin{document}
    \tableofcontents
    \section{A}
    \end{document}

and I get a message that something's wrong with '.toc' file, so what's wrong? Why does this not like amsmath package?

2
  • @egreg's answer was quicker by half a second, and more complete so I removed mine. Mar 31, 2012 at 22:40
  • Please consider accepting the answer by clicking the tick button below the voting arrows on the left side. By doing so you will conclude the question. If there is still something missing in the answer please state so. May 7, 2012 at 13:12

1 Answer 1

8

It subtly depends on the fact that amsmath redefines \@ifnextchar. In practical terms, you have a spurious space that the kernel version of that internal command removes, while the amsmath version doesn't.

\makeatletter
\renewcommand{\section}{%
  \@startsection
    {section}{1}{0mm}
    {\baselineskip}
    {\baselineskip}
    {\fontsize{14}{14}\centering\bfseries\MakeUppercase}%
}
\makeatother

Notice particularly the last % that masks the end-of-line (equivalent to a space, here). The end-of-lines from the \@startsection line until the last one need not to be masked, because \@startsection will be looking for arguments and so ignore the spaces. Putting % there does no harm, anyway.

By the way, redefining \thesection is not the best method for adding a period after the section number in a heading:

\makeatletter
\renewcommand\@seccntformat[1]{\csname the#1\endcsname.\quad}
\makeatother

is better, because \ref won't produce the number followed by a period when referring to a section number. So, here's the complete example:

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\renewcommand\@seccntformat[1]{\csname the#1\endcsname.\quad}
\renewcommand{\section}{%
  \@startsection
    {section}{1}{0mm}
    {\baselineskip}
    {\baselineskip}
    {\fontsize{14}{14}\centering\bfseries\MakeUppercase}%
       }
\makeatother
\begin{document}
\tableofcontents
\section{A}
\end{document}
2
  • 'because \ref won't produce the number followed by a period when referring to a section number' it's just an answer to the next question I had, thanks! ;)
    – Pavasaris
    Mar 31, 2012 at 22:22
  • @myname Welcome to TeX.SX, where somebody has a crystal ball that sometimes works. :)
    – egreg
    Mar 31, 2012 at 22:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .