How to keep a period after section number.

2,220 views
Skip to first unread message

Sivasubramani S

unread,
Jul 4, 2011, 7:00:21 AM7/4/11
to latexus...@googlegroups.com
Hi,

 I am writing a report using article class. In my report, there are many section and subsection. By default, we get section and subsection as

1   Introduction

1.1   Problem

whereas i want

section as

1.  Introduction

subsection as such in the default.  One more important thing i want two spaces after a period ( full stop) in the section number.

help me...



--
S Sivasubramani
Research Scholar
ESB 341, Power System Research Lab
IIT Madras, Chennai 36

Mara

unread,
Jul 4, 2011, 8:26:54 AM7/4/11
to LaTeX Users Group
Hello,
All what you need to do is adding the following commands to the
environment of your tex file, I mean before \begin{document}:

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

The first one will bring . after the section number, like: 1.
section#1, 2. Section#2, etc...
and the second one will bring . after each number, like, 1.1.
subsection#1, 1.2. subsection#2 and so on...

I hope this had replied your inquiry.
regards
Mara
On Jul 4, 7:00 pm, Sivasubramani S

Sivasubramani S

unread,
Jul 4, 2011, 9:20:56 AM7/4/11
to latexus...@googlegroups.com
This solved my problem. However, i want to reduce the white space between period and title.

i.e.,

1.     Inroduction

i want

1.  Introduction

--
You received this message because you are subscribed to the Google Groups "LaTeX Users Group" group.
To post to this group, send email to latexus...@googlegroups.com.
To unsubscribe from this group, send email to latexusersgro...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/latexusersgroup?hl=en.

Mico Loretan

unread,
Jul 4, 2011, 11:17:35 AM7/4/11
to LaTeX Users Group
Hi all,

Unfortunately, Mara's suggestion (i.e., to do a renewcommand on
\thesection and \thesubsection), solves one issue -- adding a dot
(period) after the section number in the section header -- but creates
two new ones: first, all cross-references to sections will have an
annoying (and probably unwanted!) dot as well, and the extra dot also
shows up if you have to create a Table of Contents (using the
\tableofcontents command). It also doesn't address the need to change
the space between the (sub)section header number and the (sub)section
header text.

To circumvent the newly-introduced problem is a bit more work. I
suggest you delete any \renewcommand{section/subsection/etc} commands,
load the "sectsty" LaTeX package, and add the following instructions
immediately after the \usepackage{sectsty} command:

\makeatletter
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
{\csname the#1\endcsname}% default
{\csname #1@cntformat\endcsname}}% enable individual control
\newcommand{\section@cntformat}{\thesection.\ \ }
\newcommand{\subsection@cntformat}{\thesubsection\ \ }
\newcommand{\subsubsection@cntformat}{\thesubsubsection\ \ }
\makeatother

Basically, what we have here is code to keep separate two entities
that are logically distinct: (a) the \thesection, \thesubsection, etc.
macros (defined implicitly, upon specifying the document class) store
the "values" of the section, subsection, etc. counters, and (b) the
\...cntformat macros specify how these values should be typeset in
section, subsection, etc. headers. Notice that the \...cntformat
macros specify the dot after the section (but not subsection) header
number and the two empty spaces that, according to Siva's
specifications, should separate the (sub,subsub)section header
"number" from its corresponding text.

Happy TeXing,

Mico


On Jul 4, 9:20 am, Sivasubramani S

Peter Flynn

unread,
Jul 4, 2011, 11:38:12 AM7/4/11
to latexus...@googlegroups.com
On Mon, Jul 4, 2011 at 1:00 PM, Sivasubramani S <sivasubramani...@gmail.com> wrote:
Hi,

 I am writing a report using article class. In my report, there are many section and subsection. By default, we get section and subsection as

1   Introduction

1.1   Problem

whereas i want

section as

1.  Introduction

subsection as such in the default. 

\makeatletter
\renewcommand{\thesection}{\thechapter.\@arabic\c@section.}

\makeatother
 
One more important thing i want two spaces after a period ( full stop) in the section number.

There is no such concept in typesetting as "two spaces": "space" is a measured dimension.
LaTeX already says:

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

This already gives you a quad space (twice the width of a numeral, so approximately "two spaces"). If this is not enough, add this to your Preamble:

\makeatletter
\def\@seccntformat#1{\csname the#1\endcsname\qquad}
\makeatother

But the result will look very strange.

///Peter

Peter Flynn

unread,
Jul 4, 2011, 11:39:37 AM7/4/11
to latexus...@googlegroups.com
On Mon, Jul 4, 2011 at 3:20 PM, Sivasubramani S <sivasubramani...@gmail.com> wrote:
This solved my problem. However, i want to reduce the white space between period and title.

I thought you wanted to increase it, sorry. To reduce it, use

\makeatletter
\def\@seccntformat#1{\csname the#1\endcsname\enspace}
\makeatother

///Peter
 

Sivasubramani S

unread,
Jul 4, 2011, 12:05:09 PM7/4/11
to latexus...@googlegroups.com
Both Mico and Peter ideas gave what i want. May i know the difference in two methods?



--
You received this message because you are subscribed to the Google Groups "LaTeX Users Group" group.
To post to this group, send email to latexus...@googlegroups.com.
To unsubscribe from this group, send email to latexusersgro...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/latexusersgroup?hl=en.

Mico Loretan

unread,
Jul 4, 2011, 12:40:40 PM7/4/11
to LaTeX Users Group
Siva:

The code fragments that Peter and I provided are extremely similar.
(Note that for my code it's actually not necessary to load the sectsty
package, contrary to what I wrote in my initial message.) Maybe my
code has ever so slightly more generality as it caters to your need
for inserting a dot (period) after the section number at the section
level while suppressing such behavior at the subsection and
subsubsection levels. Best, Mico

On Jul 4, 12:05 pm, Sivasubramani S

Mara

unread,
Jul 4, 2011, 8:59:42 PM7/4/11
to LaTeX Users Group
Hello Mico,

As for adding . after the number of the section:

I have tested the commands:

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

on article class, I found there is no annoying problem-as you said-
with cross references with section numbers and subsection numbers. The
figures, the tables, and even the equations all work perfectly as long
as you define the environment of the figures and the tables and the
equations.


The full definitions are:
\renewcommand\thesection{\arabic{section}.}
\renewcommand\thesubsection{\arabic{section}.\arabic{subsection}.}

\renewcommand{\theequation}{\arabic{section}.\arabic{equation}}
\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}

I also have tested the commands by removing these last two, the
numbering had went back to its original style but still everything
works fine, no extra dots, and there is no unwanted dots.

May I know what are the problems that you mention that these codes
have created?

best regards
Mara.

Mico Loretan

unread,
Jul 5, 2011, 12:59:20 AM7/5/11
to LaTeX Users Group
Hello Mara,

First off, if I've given offense to you with my earlier posting by
calling something "annoying", I apologize. My main point was to point
out (pun intended) that a seemingly plausible solution can have some
undesirable consequences -- and to provide a different solution,
naturally.

If I understand your follow-up message correctly, you contend that the
code you proposed to the list does not have the "annoying"
consequences I stated it has. I must respectfully disagree. Consider
the following minimal working example (MWE), which contains your code
in the preamble and goes on to put it to the test.
%%% mwe.tex
\documentclass{article}
\renewcommand\thesection{\arabic{section}.}
\renewcommand\thesubsection{\arabic{section}.\arabic{subsection}.}
\renewcommand{\theequation}{\arabic{section}.\arabic{equation}}
\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}
\begin{document}
\section{First section}\label{sec:1}
\subsection{First subsection of first section}\label{sec:11}
Here's a cross-reference to Section \ref{sec:2}. And here's one to
Section \ref{sec:3}.
\begin{figure}[h]\caption{Empty Figure A}\label{fig:1}\end{figure}
\begin{equation}\label{eq:einstein}
E=m\,c^2
\end{equation}

\section{Second section}\label{sec:2}
As was claimed in Section \ref{sec:1}, we must be careful to \ldots
\begin{figure}[h]\caption{Empty Figure B}\label{fig:2}\end{figure}
\begin{equation}\label{eq:euler}
e^{i\pi}-1=0
\end{equation}
\begin{equation}\label{eq:magritte}
\hbox{``This is not an equation!'' (with apologies to Ren{\'e}
Magritte)}
\end{equation}

\section{Third section}\label{sec:3}
Here's a cross-reference to Subsection \ref{sec:11}.
\begin{figure}[h]\caption{Empty Figure C}\label{fig:3}\end{figure}
\begin{equation}\label{eq:trivial}
1+1=2
\end{equation}
\end{document}
%%% end mwe.tex

Run latex on this file twice (to resolve the cross-references). Study
the output and notice that there are three problems. (i) There are
two consecutive dots when the cross-reference is at the end of a
sentence, and one dot followed immediately by a comma if the cross-
reference is followed by a comma. If the label "annoying" for the
double-dot and dot-comma issues is too harsh, how about "unwelcome" or
"undesirable"? (ii) The figures are numbered 1.1, 2.2, and 3.3,
whereas (I think) most readers would expect them to be numbered 1.1,
2.1, and 3.1. (iii) The same problem applies to the equation numbers,
which ought to appear as (1.1), (2.1), (2.2), and (3.1) but instead
show up as (1.1), (2.2), (2.3), and (3.4).

Obtaining a solution for problem (i) requires code along the lines
that Peter Flynn and I proposed in our earlier messages. Notice that
problems (ii) and (iii) both arise because the equation and figure
numbers are not reset each time a new section starts. Fortunately,
fixing these problems is very easy if the amsmath package is loaded,
by using that package's \numberwithin macro. Consider the following
MWE, in which I've simplified the code relative to the first MWE to
focus on the issue of resetting the figure and equation numbers each
time a new section starts.
%%% mwe2.tex
\documentclass{article}
\usepackage{amsmath}
\numberwithin{figure}{section}
\numberwithin{equation}{section}
\begin{document}
\section{First section}
\begin{figure}[h]\caption{Empty Figure A}\end{figure}
\begin{equation}\label{eq:einstein}
E=m\,c^2
\end{equation}

\section{Second section}
\begin{figure}[h]\caption{Empty Figure B}\end{figure}
\begin{equation}\label{eq:euler}
e^{i\pi}-1=0
\end{equation}
\begin{equation}\label{eq:magritte}
\text{``This is not an equation!'' (with apologies to Ren{\'e}
Magritte)}
\end{equation}

\section{Third section}
\begin{figure}[h]\caption{Empty Figure C}\end{figure}
\begin{equation}\label{eq:trivial}
1+1=2
\end{equation}
\end{document}
%%% end mwe2.tex


Sincerely, Mico.

Mara

unread,
Jul 5, 2011, 4:31:12 AM7/5/11
to LaTeX Users Group
Hi,

You haven't offended me. you disagree with me. we all here about
exchanging information and about learning. Anyway, what you/others
have said in this post have given me the idea for a new challenge in
latex!

Glad that the original inquiry has been answered.

Take care.
Mara

Mara

unread,
Jul 6, 2011, 10:48:11 AM7/6/11
to LaTeX Users Group
Hi,

To whom it may concern:

This very simple example would resolve both: adding the desired dots
to the sections, subsections, etc. and removing the unwanted dots from
the cross-reference.

\documentclass{article}

\renewcommand\thesection{\arabic{section}.}
\renewcommand\thesubsection{\thesection\arabic{subsection}.}
\renewcommand\thesubsubsection{\thesubsection\arabic{subsubsection}.}


\makeatletter
\renewcommand{\p@section}{\arabic{section}\expandafter\@gobble}
\renewcommand{\p@subsection}{\thesection\arabic{subsection}\expandafter
\@gobble}
\renewcommand{\p@subsubsection}{\thesubsection\arabic{subsubsection}
\expandafter\@gobble}
\makeatother

\begin{document}

\section{test}\label{test}
\subsection{subtest}\label{subtest}
\subsubsection{subsubtest}\label{subsubtest}


See section~\ref{test} and subsection~\ref{subtest} and subsubsection~
\ref{subsubtest}!

\end{document}

best regards.
Mara
> ...
>
> read more »

Mico Loretan

unread,
Jul 6, 2011, 6:31:42 PM7/6/11
to LaTeX Users Group
Mara:

At first glance, your use of the \p@section, \p@subsection, etc
commands seems to succeed in getting around the problems you
encountered earlier, i.e., having unwanted extra dots show up in cross-
references. Unfortunately, your new code introduces new problems in
the process of solving old problems.

Do study the MWE below, which uses the \appendix command. (In
appendices, section numbers are traditionally displayed in uppercase-
Alpha style, i.e., A, B, C, etc.) Run LaTeX twice on the MWE and
observe the following problems: First, cross-references to Appendix A,
as shown both in the sentence in the main body of the document and in
the header of the first subsection of Appendix A, are displayed as "1"
instead of as "A". Second, there's no "dot" after the "A" in the
header of Appendix A, creating an odd contrast to the use of such a
dot in the main body of the document. Third, the "dot" that should
separate the "A" from the "1" in the number of subsection A.1 is also
missing, and the subsection number therefore shows up as "A1". The
first problem above arises because the \p@section definition is not
changed automatically when the \thesection macro is changed (as
happens when the \appendix declaration is executed). The second and
third problems arise because the \appendix command sets \thesection as
not having a terminal "dot" (as per "normal" LaTeX style).

I suppose these new problems could be "fixed" by doing a further
\renewcommand, this time on the \appendix macro. However, doing so may
well give rise to still more follow-up problems. And we haven't even
investigated yet whether your redefinitions of the "prefix
commands" (\p@section, \p@subsection, etc) might cause problems of
their own in various documents.

OK, I think I've said enough on this topic... Cheers, Mico

\documentclass{article}
\renewcommand\thesection{\arabic{section}.}
\renewcommand\thesubsection{\thesection\arabic{subsection}.}
\renewcommand\thesubsubsection{\thesubsection\arabic{subsubsection}.}
\makeatletter
\renewcommand{\p@section}{\arabic{section}\expandafter\@gobble}
\renewcommand{\p@subsection}{\thesection\arabic{subsection}\expandafter
\@gobble}
\renewcommand{\p@subsubsection}{\thesubsection\arabic{subsubsection}
\expandafter\@gobble}
\makeatother
\begin{document}
\section{First section in main body of paper}\label{sec:mainsection}
Here's a cross-reference to main-body section~\ref{sec:mainsection},
and here's a cross-reference to appendix-part section
\ref{sec:appsection}.
\appendix
\section{First section of the appendix part}\label{sec:appsection}
\subsection{First subsection of appendix \ref{sec:appsection}}
\end{document}
> > > > > > > The first one will...
>
> read more »

Mara

unread,
Jul 7, 2011, 1:09:13 AM7/7/11
to LaTeX Users Group
Mico:

It is strange how you deal with and the way you argue on this specific
subject.

of course it will not work this way!! you are mixing the default
definitions with the modified ones.. This cannot work here.

Here we have changed the commands with respect to sections,
subsections... of course the default definition for appendix needs to
get modified too..

2 emails ago you have said that the cross-references give problems
with tables, figures, and equations. I did not comment on that
because, very funny, I didn't have or get these problems with the
tables, figures, equations and so on, you know why? Simply because in
the first place I used the right packages. Now you talk about problems
with appendix with respect to these new commands...

If I want to give you now (which I do not) the right new-commands for
the appendix problem, you will find me something else and else and
else... which is fine if we want to build up a whole new template in
latex for this specific "dot" issue. It is fine again because building
up new templates in different languages around the world is fantastic.
But lucky for me and for my time, we are not doing this right now.


So to end this: As you probably know, everything can be fixed in latex
with using the appropriate packages and and commands, if that does not
work with normal existing commands, then we have to create new ones to
make it work!

My apology beforehand if I offend you.

See you hopefully with another worthy problem in latex
Take care for now
Mara.
> ...
>
> read more »
Reply all
Reply to author
Forward
0 new messages