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.

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?

share|improve this question

3 Answers 3

up vote 5 down vote accepted

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

share|improve this answer

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.

share|improve this answer

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} 
share|improve this answer

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.