[Tex/LaTex] Align custom chapter heading to the left

chapterssectioning

I am using a custom calss called ufpethesis, based on the book class, to format my masters thesis.

My aim is to insert the chapter numbering to the left of the chapter title, have it aligned to the left margin and preserve the custom headerline.

I have attempted to change the \@makechapterhead and \@makeschapterhead as well as subsections definitions, as pointed out in a related post How to format the chapter heading?. Here follows my attempt's output (to the left) and the original output (to the right).

make

As you can see, I have introduced some space when I tried to insert the chapter numbering, shifting both the headerline and chapter title to the right. The same happens in the starred version of the command:

makes

Any ideas on how to fix this?

Here's my MWE:

\documentclass[oneside,msc]{ufpethesis}

\usepackage{lipsum}

\makeatletter
\def\thickhrule{\leavevmode \leaders \hrule height 1ex \hfill \kern \z@}
\def\position{\centering}

\renewcommand{\@makechapterhead}[1]{
\global\topskip 1.5pc
  \relax
  \begingroup
  \ignorespaces
  \LARGE\bfseries \thechapter\enspace 
    \ifnum\c@secnumdepth>\m@ne
      \leavevmode \hskip-\leftskip 
      \rlap{\vbox to\z@{\vss
          \centering\large\sc{\chaptername}\enspace\thechapter
          \vskip2.5pc}}\hskip\leftskip\fi
     #1\par \endgroup
  \skip@4pc \advance\skip@-\normalbaselineskip
  \vskip\skip@ }  


\def\@makeschapterhead#1{
\global\topskip 1.5pc\relax
  \begingroup
  \LARGE\bfseries %\centering
   #1\par \endgroup
  \skip@4pc \advance\skip@-\normalbaselineskip
  \vskip\skip@ }

\def\section{%
  \@startsection{section}{1}{0mm}{1.5\baselineskip}
    {\baselineskip}{\large\bfseries}}

\def\subsection{%
  \@startsection{subsection}{2}{0mm}{1.2\baselineskip}
    {.6\baselineskip}{\bfseries}}

\def\subsubsection{%
  \@startsection{subsubsection}{3}{0mm}{\baselineskip}
   {.6\baselineskip}{\normalfont}}

\def\paragraph{%
  \@startsection{paragraph}{4}{0mm}{\baselineskip}
   {-1em}{\itshape}}

\def\colophon{%
  \if@openright\cleardoublepage\else\clearpage\fi
  \thispagestyle{empty}
  \null\vfill
  \small\noindent
  \@colophontext    
}


\def\abstract{%
  \gdef\@keywordsname{\keywordsnameEN}
  \chapter*{\centerline\abstrname}}

%% Inicio do documento
\begin{document}

\chapter{Capitulo segundo}
\section{Trial}
\section{Seção especial}
Teste

\end{document}

Here's also a version hosted on sharelatex.

Best Answer

Without the proper knowledge of basic TeX the answer I came up with involves the package titlesec, thanks to @Bernard's suggestion. I managed to adjust the output to my taste. A mwe with these adjustments and the outcome can be found below:

\documentclass[oneside,msc]{ufpethesis}

%% Preamble
\usepackage{lipsum}   % Cria texto "miolo de pote"
\usepackage{titlesec} % Modifica títulos

% Title adjustments (appearance and spacking)
\titleformat{\chapter}[hang]
{\LARGE\normalfont\bfseries}
{\thechapter}{0.5em}{}
\titleformat{name=\chapter,numberless}[hang]
  {\normalfont\LARGE\bfseries\filcenter}{}{1ex}{}{}
\titleformat{\section}[hang]{\normalfont\bfseries}{\thesection}{0.5em}{}
\titleformat{\subsection}[hang]{\normalfont\bfseries}{\thesubsection}{0.5em}{}
\titleformat{\subsubsection}[hang]{\normalfont\bfseries}{\thesubsubsection}{0.5em}{}
\titleformat{\paragraph}[hang]{\normalfont\bfseries}{\theparagraph}{0.5em}{}
\titlespacing{\chapter}{0pt}{0pt}{40pt}
\titlespacing{\section}{0pt}{\baselineskip}{0.625\baselineskip}
\titlespacing{\subsection}{0pt}{\baselineskip}{0.6\baselineskip}
\titlespacing{\subsubsection}{0pt}{\baselineskip}{\baselineskip}
\titlespacing{\paragraph}{0pt}{\baselineskip}{\baselineskip}

\begin{document}

\chapter{Capitulo segundo}
\section{Trial}
\section{AnotherTrial}
\subsection{Seção especial}
\subsubsection{Meu teste}
\paragraph{Paragrafo teste}

\end{document}

Outcome:

enter image description here