Make Sections Look Like Book Chapters – How to Style Section Numbers as Book Chapters in LaTeX

sectioning

Is it possible ot increase the size of the number of a section, while also slightly increasing the size of the section text. Now, when we are using the standard \section and \subsection within \begin{document} looks like the following:

enter image description here

What we would like is to have something look like the following, where the number of the section is much larger than the text, and the section text font is also increased in size. The subsection can stay as they already are.

enter image description here

UPDATE

The section are as we wanted them to be now, but it messed up or head of every page. We use \pagestyle{fancy} but it seems like it doesn't work well together with the titlesec library because if we remove the \usepackage{titlesec}, then my header is visible and contains Validation of Meteorological Data by Machine Learning, but when adding \usepackage{titlesec}, the header just writes 0. like that, which is very odd to us.

This is the main file:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel} 
\usepackage{graphicx}
\usepackage{titling}
\usepackage{float}
\usepackage{layout}
\usepackage{makecell}
\usepackage{geometry}
\usepackage{titleps}
\usepackage{fancyhdr}
\usepackage{vmargin}
\usepackage{hyperref}
\usepackage{xcolor}

\usepackage{titlesec}

 \hypersetup{
     colorlinks=true,
     linkcolor=blue,
     filecolor=blue,
     citecolor = black,      
     urlcolor=blue,
     }

\title{Validation of Meteorological Data by Machine Learning}
\author{Ahmad Josef Sahebzadeh\\}
\date{\today}

\renewcommand\theadfont{\normalsize}

\renewcommand\theadalign{bc}
\renewcommand\theadfont{\bfseries}
\renewcommand\theadgape{\Gape[4pt]}
\renewcommand\cellgape{\Gape[4pt]}

\newcommand{\height}{6cm}

\setmarginsrb{3 cm}{1 cm}{4 cm}{2.5 cm}{1 cm}{1.5 cm}{1 cm}{1.5 cm}

\pagestyle{fancy} %THIS DOESNT WORK WITH TITLESEC
\fancyhf{} %THIS DOESNT WORK WITH TITLESEC
\lhead{\thetitle} %THIS DOESNT WORK WITH TITLESEC

\begin{document}

\pagenumbering{gobble}

\input{front}

\newpage

\input{introduction}

\end{document}

This is how it looks before adding \usepackage{titlesec}:

enter image description here

This is how it looks after adding \usepackage{titlesec}:

enter image description here

Best Answer

You can use the titlesec package.

MWE:

\documentclass{article}

\usepackage{titlesec}

\titleformat{\section}{\bfseries\LARGE}{\hspace{1ex}\Huge\thesection}{2ex}{}

\begin{document}
\section{Intro}
\subsection{Motive}
\end{document}

enter image description here

Edit: There is some compatibility issue between the fancyhdr and the titlesec package. So, to use the solution with titlesec package, I will recommend to use the titleps package which is an alternative to fancyhdr package. When combined with titlesec package, it should be loaded by using \usepackage[pagestyles]{titlesec}.

To apply the changes in the header and the footer, the syntax of the titleps package is:

\sethead[heven-lefti][heven-centeri][heven-righti]
{hodd-lefti}{hodd-centeri}{hodd-righti}

You may go through this page to find some examples with titleps.

For some reason, the \thetitle from the \titling package didn't work with the \titlesec package. So, I inserted the title of the article directly.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel} 
\usepackage{graphicx}
\usepackage{titling}
\usepackage{float}
\usepackage{layout}
\usepackage{makecell}
\usepackage{geometry}
\usepackage[pagestyles]{titlesec} % <------ changed
% \usepackage{titleps} % <------ changed
% \usepackage{fancyhdr} % <------ changed
\usepackage{vmargin}
\usepackage{hyperref}
\usepackage{xcolor}
\usepackage{lipsum}


 \hypersetup{
     colorlinks=true,
     linkcolor=blue,
     filecolor=blue,
     citecolor = black,      
     urlcolor=blue,
     }

\title{Validation of Meteorological Data by Machine Learning}
\author{Ahmad Josef Sahebzadeh}
\date{\today}

\renewcommand\theadfont{\normalsize}
\renewcommand\theadalign{bc}
\renewcommand\theadfont{\bfseries}
\renewcommand\theadgape{\Gape[4pt]}
\renewcommand\cellgape{\Gape[4pt]}
\newcommand{\height}{6cm}

\setmarginsrb{3 cm}{1 cm}{4 cm}{2.5 cm}{1 cm}{1.5 cm}{1 cm}{1.5 cm}

% ---------------- changed -------------------
\settitlemarks{section,subsection}
\newpagestyle{myFancy}[\normalsize\bfseries]{
    \setheadrule{0.4pt}%
    \sethead[\ifthesection{Validation of Meteorological Data by Machine Learning}{Validation of Meteorological Data by Machine Learning}]%
    [][]%
            {\ifthesection{Validation of Meteorological Data by Machine Learning}{Validation of Meteorological Data by Machine Learning}}%
            {}{}%
}


\titleformat{\section}{\bfseries\LARGE}{\hspace{1ex}\Huge\thesection}{2ex}{}

\pagestyle{myFancy}
% ---------------- changed -------------------

\begin{document}
    \pagenumbering{gobble}
    \section{Intro}
    \lipsum[1-5]
    \newpage
    \lipsum[6-8]
    \section{Section 2}
    \lipsum[1-5]
\end{document}

enter image description here

Note: Consider reading how to write an MWE. This will help you to get help quickly and effectively from this site.

Related Question