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 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?

share|improve this question
    
@egreg's answer was quicker by half a second, and more complete so I removed mine. –  David Carlisle Mar 31 '12 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. –  Martin Scharrer May 7 '12 at 13:12
add comment

1 Answer

up vote 8 down vote accepted

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}
share|improve this answer
    
'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 '12 at 22:22
    
@myname Welcome to TeX.SX, where somebody has a crystal ball that sometimes works. :) –  egreg Mar 31 '12 at 22:23
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.