2

I want the titles of sections and subsection to align on the same line (red in the picture):

enter image description here

How can I do it, preferably, without a package (titlesec for example)? I.e., by modifying the commands \@seccntformat and/or \@startsection?

In the following MWE, I insert the same \hskip after \thesection AND \thesubsection:

\documentclass{book}
\makeatletter
  \renewcommand{\@seccntformat}[1]{%
  \csname the#1\endcsname\hskip 15pt}
\makeatother

\begin{document}
\section{one}
\subsection{a}
Lorem ipsum, text text text
\section{two}
\subsection{b}
\end{document}

1 Answer 1

4

You need to allocate a fixed amount of space for the (sub)section counter typesetting. Here I chose 40pt; however, if your section or subsection numbering extend into double digits, you may need to revise that value.

\documentclass{book}
\makeatletter
  \renewcommand{\@seccntformat}[1]{%
  \makebox[40pt][l]{\csname the#1\endcsname}}
\makeatother

\begin{document}
\section{one}
\subsection{a}
Lorem ipsum, text text text
\section{two}
\subsection{b}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .