# \section formatting

I am trying to format my \section command in order to get a result like :

"Partie" is a piece a text I want to see everytime. Then "1" corresponds to the section number, and "Introduction" to the section title.

I have found two differents things :

• A way to draw a line under "Partie 1" :
\usetikzlibrary{calc}
\begin{center}
\begin{tikzpicture}[my node/.style={anchor=base,inner sep=0pt}]
\node[my node] (center) {Partie \thesection};
\draw($(center.base)+(-1.9cm,-1ex)$)     -- ($(center.base)+(+1.9cm,-1ex)$);
\end{tikzpicture}
\end{center}

• A way to change the format of \section :
\makeatletter
\renewcommand\section{\@startsection {section}{1}{\z@}%
{-3.5ex \@plus -1ex \@minus -.2ex}%
{2.3ex \@plus.2ex}%
{\normalfont\scshape}}
\makeatother


But I don't know how to mix those two ideas !

I'm using {book} documentclass. Even though it looks like "Partie 1 Introduction" is on a full page, it is not supposed to be the case. It is only a centred \section title with a line under.

Thank you all in advance !

• Most LaTeX classes know a command called \part that may already be closer to what you want than \section. Apr 3 '20 at 13:46
• Which documentclass do you use? Should "Partie 1 Introduction" occupy a page on its own? If so, you might be interested in modifying the \part command instead. Apr 3 '20 at 13:46
• Hi everyone ! Im using \documentclass[12pt,twoside,draft]{book} Unfortunately I am already using \part and \chapter. But "Partie 1 Introduction" is not supposed to use a full page ! Apr 3 '20 at 13:52
• I am editing my post in order to add the documentclass I'm using and the fact that it is not supposed to use a full page. Apr 3 '20 at 13:53

Welcome to TeX.SE...

Do you really this head belongs as \section, not sure. Anyhow, hope the below MWE may helps you...

\documentclass{book}
\usepackage{titlesec}

\begin{document}
\titleformat{\section}[block]
{\normalfont\bfseries\filcenter}{\textsc{Partie}\ \thesection\\\rule{\textwidth}{0.5pt}}{1em}{}

\section{Test}

\end{document}


Update

\titleformat{\section}[block]
{\normalfont\bfseries\filcenter}{\textsc{Partie}\
\thesection\\\rule{3cm}{0.5pt}\\}{1em}{}

• Thank you for your answer ! It is almost perfect : the line has to be 3cm wide : when I change "\textwidth" by "3cm", the line and "Introduction" are side to side... Any idea ? Apr 3 '20 at 14:00
• @Guliup Check the Update suggestion... Apr 3 '20 at 14:05
• Thats perfect ! Apr 3 '20 at 14:23
• @Guliup Glad to help you, if the suggestion suits with your requirement, then please accept the answer by clicking the tick mark... Apr 3 '20 at 14:28
• You are the best :) Apr 3 '20 at 15:11