4

My sections are numbered with a dot after counter. I get it like this

\renewcommand{\thesection}{\arabic{section}.}

I also need the equations to be numbered within sections and I try to do it like this

\numberwithin{equation}{section}

The result is that I get numbers of equations with an extra dot, e.g. (1..1) instead of (1.1).

How can I fix this?

3 Answers 3

7

If you add a closing dot the the definition of \thesection, you should also remove the "middle" dot from definitions using \thesection, especially \theequation and \thesubsection. (Note that your redefinition of \thesection will also produce a closing dot in the table of contents, the header/footer, and cross references.)

\documentclass{article}

\usepackage{amsmath}

\renewcommand{\thesection}{\arabic{section}.}
\numberwithin{equation}{section}

\renewcommand{\theequation}{\thesection\arabic{equation}}
\renewcommand{\thesubsection}{\thesection\arabic{subsection}}

\begin{document}

\section{foo}

\subsection{bar}

\begin{equation}
a^2 + b^2 = c^2
\end{equation}

\end{document}

EDIT: In response to Frank Mittelbach, here's an alternative that changes the \@seccntformat macro so that it adds a dot if the new \@seccntdot conditional is true. The etoolbox package is used to set this conditional to true before \section and to false after every equal/lower-level sectioning command.

\documentclass{article}

\usepackage{amsmath}

\numberwithin{equation}{section}

\usepackage{etoolbox}

\makeatletter

\newif\if@seccntdot

\pretocmd{\section}{\@seccntdottrue}{}{}
\apptocmd{\@xsect}{\@seccntdotfalse}{}{}

\def\@seccntformat#1{%
  \csname the#1\endcsname
  \if@seccntdot .\fi
  \quad
}

\makeatother

\begin{document}

\section{foo}

\subsection{bar}

\begin{equation}
a^2 + b^2 = c^2
\end{equation}

\end{document}

Output for both examples:

enter image description here

6

As it was already mentioned by @lockstep changing \thesection in this manner means that the extra dot is added whereever \thesectionis being used (which is in various places) and for example in cross references or in the TOC this is probably not desired.

One possible alternative is to change the command \@seccntformat which is used by the standard heading commands to format the number of th heading itself (but nowhere else). Its default definition is

\def\@seccntformat#1{\csname the#1\endcsname\quad}

The dot could be easily added there, however it would then apply to all headings produced with \@startsection, e.g., \section, \subsection, ... unless you build in some logic that provides different results depending on the argument.

3

Another simple alternative is to use a feature of the »titlesec« package to add the dot to the heading.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}   % loads »amsmath«
\usepackage{titlesec}

\numberwithin{equation}{section}

\titleformat{\section}{\normalfont\Large\bfseries}{\thesection.}{1em}{}

\begin{document}
  \section{Foo}
    \subsection{Bar}

      \begin{equation}
        a^2+b^2=c^2
      \end{equation}
\end{document} 

You must log in to answer this question.

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