I would like to have a fixed distance from the beginning of the section number to the section title. Visually, I expect all section and subsection numbers and titles to line up vertically as if they were justified to the left in invisible two columns. However, the default behaviour of titlesec
is to add fixed distance after the end of the number so I get numbers justified to the left, but titles are a fixed distance from the end of the number.
I have experimented a bit with parbox
, which gives me the visual effect I am after, but I think this creates a parbox on the title rather than a number and there's some vertical translation, which I tried to tackle manually with raisebox
, but quite ineffectively.
My MWE:
\usepackage{lipsum}
\usepackage{titlesec}
\titleformat{\section}[hang]{\Large\bfseries}{\raisebox{0pt}{\parbox{20pt}{\thesection}}}{0pt}{}
\titleformat{\subsection}{\bfseries}{\raisebox{-0.25pt}{\parbox{20pt}{\thesubsection}}}{0pt}{}
\makeatletter
\makeatother
\begin{document}
\section{First section}
\subsection{A subsection}
\lipsum[1]
\subsection{Another subsection}
\lipsum[2]
\section{Another section}
\lipsum[3]
\end{document}
I would appreciate some advice on this. Thanks!