Home > sectioning > An extra dot after section counter while numbering equations

# An extra dot after section counter while numbering equations

May 21Hits:6

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?

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}

$$a^2 + b^2 = c^2$$

\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\[email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */

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

\def\@seccntformat#1{%
\csname the#1\endcsname
\[email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */ .\fi
}

\makeatother

\begin{document}

\section{foo}

\subsection{bar}

$$a^2 + b^2 = c^2$$

\end{document}



Output for both examples:

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.

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{titlesec}

\numberwithin{equation}{section}

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

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

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



## Related Articles

• ### An extra dot after section counter while numbering equationsMay 21

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 t

• ### Exsheets: how to get a counter/reference combining section and question numbersAugust 27

I am writing a document that has several major sections, and each section will have some exercises and solutions. I am using the exsheets package, which seems to do almost everything I want. However, I'm puzzled about how to get my numbering and refe

• ### theorem numbering : section counter but remove the section numberOctober 17

I'm searching how to remove the chapter+section number on the theorem numbering with a section counter. With no section counter it's like: \newtheorem{thm}{Title} Chapter1 ----Section 1 --------thm 1 --------thm 2 ----Section 2 --------thm 3 --------

• ### How to add dot after \section number in headline and ToC, without adding dot to \ref commandMay 12


• ### Appendix changes sections and figures numberingApril 10

I don't know how to face a strange behavior caused by the appendix package. I'm using KOMA-Script book class and many other packages (see here: http://pastie.org/1728702) When I add an appendix (not the package, the \appendix command or the appendix

• ### Is it possible to customize only the section and subsection numbers or titles in memoir?September 27

Like the question title says, is it possible to customize only the section and subsection numbers or titles in memoir? I know how to change the font for the entire block, but I would like to make the section numbers a bit smaller compared to the sect

• ### How remove dot after section number in ToC with babel's spanish?September 25

I'm using the book document class and the babel package with the spanish option, I have a ToC like this: CHAPTER NAME 1.1. SECTION NAME 1.1.1. Subsection name 1.1.1.1. Subsubsection name How can I remove the dot after sections numbers, tables numbers

• ### Wrong section counter for references when using titlesecOctober 14

Changing the style of my sections using the package titlesec works fine with these lines \usepackage{titlesec} \titleformat{\section}[block]{\large\scshape\centering{\Roman{section}.}}{}{1em}{} but after adding my literature to the end of the file...

• ### xr - temporarily redefine \label for exporting section counter to sister document?July 13

The goal My objective is to have continuous page (and possibly section) counters for several independent documents. The purpose is a cumulative dissertation where each paper should retain the journal's layout as much as possible, but the school requi

• ### How to reset section counterJuly 19

This is the barebones of my document: \documentclass[12pt]{article} \begin{document} \begin{center} \textbf{\LARGE{Topic I}} \end{center} \section{Section I} content \section{Section II} content \subsection{Subsection I} content \subsection{Subsectio

• ### Section and subsection numberingAugust 1

I'm new to LATEX language and now a have a problem with section and subsection numbering. I want to make my text look like this: 1. Sun 1.1 Moon 2. Bed I was tried to figure out how to make it, but it doesn't work for me. This is my code: \documentcl

• ### Whys is there extra dot at the start of some command I'm supposed to execute November 4

This question already has an answer here: Using '.' to execute files in bash 4 answers I've downloaded an installation package of weblogic server and in the README, there's this command to execute: Linux/Mac \$ . ./configure.sh It's not the first time

• ### How can I number theorems in introduction without section counter and later with it?May 16

I would like to have my theorems numbered in the following way. Theorem 1. Blah-blah Theorem 2. More blah-blah Section 1. Theorem 1.1. Special blah Theorem 1.2. More special blah Section 2 Theorem 2.1. Another special blah and so on, preferably using

• ### Dots after section number in TOCAugust 26

I am writing my thesis in Lyx and my supervisor has very specific editing requirements. He wants that the chapter number in ToC would be followed by dot, but section numbers not. Here's code from document class: \NeedsTeXFormat{LaTeX2e} \def\@basecla

• ### How to redefine the section counter in amsart? August 17

This question already has an answer here: Continuous v. per-chapter/section numbering of figures, tables, and other document elements 2 answers I'm using the document class amsart, which defines the section counter as follows: \newcounter{section} Ho

• ### How to add a new section to a numbered list in MS Word?April 20

In Word how can I add a section into a numbered list? I have a large software requirements document that is organized using a numbered list, so I have a few paragraphs as 1, then maybe some sub-points as 1.1, 1.2, 1.3. I am having trouble where Word

• ### Own Section command working numbered and unnumberedSeptember 30

I use the following command to have section headings with subtitles \newcommand{\Section}[2]{\section[#1]{#1\\\small »#2«}} But now I only can have numbered sections because the * doesn't work for my own command. How can I have my command working bot

• ### Section Counter: 0.1 steps, starting at 1.1November 25

I'm using \part* and \section in order to formate my file. The problem is now, that \section just countrs from 1 to n. But what I actually need is the sections counting from 1.1 to 1.n, and then, after the second \part start over as 2.1 to 2.m. I use

• ### Setting section counterApril 30

I am writing a lab report and there are four "questions" corresponding to lab instructions 6.1 through to 6.4. How can I set the section counter to start at 6.1 and then continue in 0.1 increments? I would like to avoid using environments like e

• ### Counting which numbers fall in a certain bracketJune 4

I'm taking a text file that looks like this: 77, 66, 80, 81 40, 5, 35, -1 51, 58, 62, 34 0, -1, 21, 18 61, 69, 58, 49 81, 82, 90, 76 44, 51, 60, -1 64, 63, 60, 66 -1, 38, 41, 50 69, 80, 72, 75 and I'm counting which numbers fall in a certain bracket: