# Tab stops and consistent indentation in headings

I'm trying to create a documentclass that has some unusual headings and indentation. My goal is to have the width of chapter/section number + whitespace equal to the text \leftskip 2.5cm. I get an almost acceptable result with the titlesec package, setting some eyeballed \hspace values (2.1cm and 1.9cm in example) to chapter and section titles, but as you can see from my example, it breaks when the heading number gets bigger.

In a visual word processor I'd just insert a tab character after the heading number and set the tab stop to 2.5cm and I'm looking to replicate this in LaTeX. I know something about the tabbed environment, but I cannot figure out how to apply it in this context with the titlesec config.

\documentclass[12pt,a4paper]{report}
\usepackage{lipsum}
\usepackage{titlesec}

\newlength\extramargin
\setlength\extramargin{2.5cm} % Regular text indent
\setlength\leftskip{\extramargin}

\titleformat{\chapter}[hang]
{\normalfont\sffamily\bfseries}
{\thechapter.\hspace{2.1cm}} % incorrect indent if chapter > 9
{0pt}
{\uppercase}
[\titlerule]
\titlespacing{\chapter}{0pt}{2em}{1em}

\titleformat{\section}[hang]
{\normalfont\sffamily\bfseries}
{\thesection\hspace{1.9cm}} % incorrect indent if section > 9
{0pt}
{}

\makeatother

\begin{document}

\chapter{Chapter title}

\section{Section}

\lipsum[1]

\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}

Oh no!

\end{document}


\titleformat{\section}[hang]

Adjust 2.1cm as you wish.