[Tex/LaTex] How to add dot after \section number in headline and ToC, without adding dot to \ref command

hyperrefnumberingsectioning

I need \section (\subsection, \subsubsection …) titles printed with dot after numbering.

Example:

  1. My Title

For this purpose i use:

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

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

\renewcommand\thesubsubsection{\thesubsection\arabic{subsubsection}.}

\renewcommand\theparagraph{\thesubsubsection\arabic{paragraph}.}

But this method also adds extra dot to \ref{} commands. So code "Look at section \ref{section:label}." produces string "Look at section 3.."

Is there any way to add dot only to headlines and ToC, but not to references?

Best Answer

Here is how to do with titlesec/titletoc. The dot after the label is added by \titleformat, not by \thesection. As for the dot in the table of contents, it is an option in titletoc. In addition, I use cleveref for a simpler writing of cross-references.

\documentclass[12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{heuristica}
\usepackage{lipsum}
\usepackage{titlesec}
\usepackage[dotinlabels]{titletoc}
\titleformat{\section}[hang]{\bfseries\large}{Section \thesection.}{0.4em}{}
\titlespacing*{\section}{0pt}{2\baselineskip}{2\baselineskip}
\dottedcontents{section}[3.8em]{}{2.3em}{1pc}
\usepackage{cleveref}

\begin{document}

\tableofcontents

\section{Preliminaries}\label{sec:prelim}
\lipsum[1]

\section{Another section}
See \Cref{sec:prelim}.

\end{document} 

enter image description here

Related Question