0

I would like to frame the content of \part.

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[left=1.8cm,right=1.8cm,top=2cm,bottom=2cm]{geometry}
\begin{document}
\tableofcontents
\newpage
\part{Cours}
\section{test part}
\end{document}

enter image description here

Do you have a fancy way to frame it ? Thanks

Tony
  • 101
  • 5
  • Welcome to TeX.SE. Clarification question: do you want to draw a frame around the word Cours, or around the words Première partie, or one frame around both, or a frame around everything in the part up to the next part (so including the section title and text below, i.e., the whole page until the following \part command)? – Marijn Nov 09 '22 at 10:31
  • Thank you for your feedback!! If the answer meets your requirement, please accept it by checking the green tickmark on left side of the answer. – Simon Dispa Nov 15 '22 at 12:44

1 Answers1

2

One possible way to add a fancy frame is by using the tcolorbox package.

The size of the box will adjust to its content. It's pretty easy to change colors, text alignment, and other properties.

b

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}

\usepackage[french]{babel}

\usepackage[left=1.8cm,right=1.8cm,top=2cm,bottom=2cm]{geometry}

% ***************************************** added <<<<<<<<<<<<<<<< \usepackage[most]{tcolorbox}

\newtcbox{\partbox}[1][]{% colback=blue!5!white,colframe=blue!75!black, % colors <<<<<<<<<<<<<<<<<<<<<< tikznode= {align =left}, % text align <<<<<<<<<<<<<<<<<<<<<< nobeforeafter, tcbox raise base}

\makeatletter \def@part[#1]#2{% \ifnum \c@secnumdepth >\m@ne \refstepcounter{part}% \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}% \else \addcontentsline{toc}{part}{#1}% \fi {\parindent \z@ \raggedright% \interlinepenalty @M% \normalfont \partbox{\Large\bfseries \partname~\thepart \[1ex] \huge \bfseries #2}
\markboth{}{}\par}% \nobreak\vskip 3ex@afterheading}

\def@spart#1{% {\parindent \z@ \raggedright \interlinepenalty @M \normalfont \partbox{\huge \bfseries #1}\par}% \nobreak\vskip 3ex @afterheading} \makeatother % *****************************************

\begin{document} \tableofcontents \newpage \part{Cours} \section{test part}

\part{Nouveau matériel}

\part*{La fin}

\end{document}

You can get a vanilla style using

\newtcbox{\partbox}[1][]{% vanilla style
    colback=white, colframe= black,
    sharp corners,
    tikznode= {align =left}, % text align <<<<<<<<<<<<<<<<<<<<<<
    nobeforeafter,  tcbox raise base }

c

Option

Instead of modifying \@part you can define a new command \fpart and use e.g. as \fpart{Cours}

\newcommand{\fpart}[1]{%
    \refstepcounter{part}%
    \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \noindent\partbox{\normalfont\Large\bfseries \partname~\thepart \\[1ex] \huge \bfseries #1} 
    \markboth{}{}%
}
Simon Dispa
  • 39,141
  • 1
    Maybe good to mention that you can use this approach as well if you want a non-fancy frame, i.e., black line, no fill color, non-rounded corners, by changing the relevant tcbox options. – Marijn Nov 09 '22 at 19:46
  • Thank you for helping me ! – Tony Nov 10 '22 at 10:46
  • Hello it's me again. I have a new problem : my part title is too long to fit in one line. How can the command be modified to write this title in 2 or more lines ? – Tony Jan 09 '23 at 14:43