Hide section numbers, but keep numbering
Redefining \thesection
is not sufficient. This will do better: the section title will be aligned to the left margin and not indented; in the table of contents, the section title will appear horizontally aligned to the chapter titles.
\documentclass{book}
\renewcommand{\thesection}{}
\renewcommand{\thesubsection}{\arabic{section}.\arabic{subsection}}
\makeatletter
\def\@seccntformat#1{\csname #1ignore\expandafter\endcsname\csname the#1\endcsname\quad}
\let\sectionignore\@gobbletwo
\let\latex@numberline\numberline
\def\numberline#1{\if\relax#1\relax\else\latex@numberline{#1}\fi}
\makeatother
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{Title}
\section{Xyz}
\subsection{Here we are}
\end{document}
I think your best bet is to redefine \thesection
, which is the macro that normally prints the section number.
\renewcommand\thesection{}
If you want subsection numbers to include the section numbers that aren't getting printed, you will also need to redefine \thesubsection
, which normally calls \thesection
:
\makeatletter
\renewcommand\thesection{}
\renewcommand\thesubsection{\@arabic\c@section.\@arabic\c@subsection}
\makeatother
If you're using a KOMA-script document class (e.g., scrartcl
), then for normal behaviour, just not showing section numbers, include in your preamble
\renewcommand*{\sectionformat}{}
This also works for \chapterformat
(if you're using scrbook
or scrreport
), \partformat
, all the way down to \subparagraphformat
.
The counter counts the section despite the number label not being shown, so TOC, PDF bookmarks, and subsection numbering all operate as they should (tested with hyperref
and bookmark
packages loaded.)