11

I'd like my section headings to be displayed directly after the section numbering with no space in between. This should be the case regardless of the number. Something like this:

1. A section heading
2. Another section heading
...
1526. Yet another section

Currently I'm using titlesec with

\titleformat{\section}{\large\bfseries}{\makebox[1pt][l]{\thesection}}{12pt}{}

but this causes heading and large numbers to overlap.

Jakub
  • 355

2 Answers2

9

Update: there's an easier solution with titlesec: the \thetitle command is respectively \thesection, \thesubsection, etc. The default value in standard classes is:

\titlelabel{\thetitle\quad}

which means that after the number, an space of 1em is inserted; to change this behaviour is enough then to redefine \thetitle to add a dot and then a space:

\titlelabel{\thetitle.\ }

A complete example:

\documentclass{article}
\usepackage{titlesec}

\setcounter{secnumdepth}{5}% just for the example

\titlelabel{\thetitle.\ }

\begin{document}

\section{Test Section}
\subsection{Test Subsection}
\subsubsection{Test Subsubection}
\paragraph{Test Paragraph}
\subparagraph{Test Subparagraph}

\section*{Test Section}
\subsection*{Test Subsection}
\subsubsection*{Test Subsubection}
\paragraph*{Test Paragraph}
\subparagraph*{Test Subparagraph}

\end{document}

enter image description here

One possibility using the titlesec package affecting \section through \subparagraph:

\documentclass{article}
\usepackage[explicit]{titlesec}

\setcounter{secnumdepth}{5}% just for the example

\titleformat{\section}
  {\normalfont\Large\bfseries}{\thesection.}{0em}{~#1}
\titleformat{name=\section,numberless}
  {\normalfont\Large\bfseries}{}{0em}{#1}
\titleformat{\subsection}
  {\normalfont\large\bfseries}{\thesubsection.}{0em}{~#1}
\titleformat{name=\subsection,numberless}
  {\normalfont\large\bfseries}{}{0em}{#1}
\titleformat{\subsubsection}
  {\normalfont\normalsize\bfseries}{\thesubsubsection.}{0em}{~#1}
\titleformat{name=\subsubsection,numberless}
  {\normalfont\normalsize\bfseries}{}{0em}{#1}
\titleformat{\paragraph}[runin]
  {\normalfont\normalsize\bfseries}{\theparagraph.}{0em}{~#1}
\titleformat{name=\paragraph,numberless}[runin]
  {\normalfont\normalsize\bfseries}{}{0em}{#1}
\titleformat{\subparagraph}[runin]
  {\normalfont\normalsize\bfseries}{\thesubparagraph.}{0em}{~#1}
\titleformat{name=\subparagraph,numberless}[runin]
  {\normalfont\normalsize\bfseries}{}{0em}{#1}

\begin{document}

\section{Test Section}
\subsection{Test Subsection}
\subsubsection{Test Subsubection}
\paragraph{Test Paragraph}
\subparagraph{Test Subparagraph}

\end{document}

I can't upload images; will do it later.

Gonzalo Medina
  • 505,128
8

The simplest way, without any package, is to redefine \@seccntformat, which usually adds \quad after the section number:

\documentclass{article}
\usepackage[pass,showframe]{geometry}
\makeatletter
\def\@seccntformat#1{\csname the#1\endcsname.\ }
\makeatother

\setcounter{secnumdepth}{10}

\begin{document}
\section{Test Section}
\subsection{Test Subsection}
\subsubsection{Test Subsubection}
\paragraph{Test Paragraph}
\subparagraph{Test Subparagraph}
\section*{Test Section}
\subsection*{Test Subsection}
\subsubsection*{Test Subsubection}
\paragraph*{Test Paragraph}
\subparagraph*{Test Subparagraph}
\end{document}

The \ command after the dot ensures that the space is not affected by the space factor; so the space doesn't grow if \nonfrenchspacing, the default setting in LaTeX, is in force: it's a normal interword space in the current font.

I've used geometry only to add the frame; the setting of secnumdepth is only for demonstration purposes, I don't recommend going too deep in the numbering of sectional units.

enter image description here

egreg
  • 1,121,712