[Tex/LaTex] Attractive chapter titles and sections styles

boxeschapterssectioningtcolorboxtikz-styles

I came across a website where i found this attractive design for chapter titles and sections.

https://webusers.imj-prg.fr/~leonardo.zapponi/leo_divers/Agreg/Matrices_normales.pdf

enter image description here

Here's my attempt at reproducing it

\documentclass[12pt,a4paper]{report}
\usepackage{tikz}
\tikzstyle{a} = [text width=\textwidth-1cm,rectangle,draw=orange,rounded corners=2mm,line width=1pt,fill=orange!5,minimum width=\textwidth,align=left,inner sep=5mm]
\tikzstyle{b} = [rectangle,draw,rounded corners=2mm,line width=.5pt,fill=orange!25,minimum height=0mm,align=left,inner sep=2mm,font=\bfseries]
\def\titlebox#1#2{%
\begin{tikzpicture}
\node[a](a){#2};
\node[b,right=3mm](b) at (a.north west){#1};
\node[b,left=3mm](b) at (a.south east){2015-2016};
\end{tikzpicture}
}
\def\lembox#1#2{%
\begin{tikzpicture}
\node[a](a){#2};
\node[b,right=3mm](b) at (a.north west){#1};
\end{tikzpicture}
}
\parindent=0mm
\begin{document}
\titlebox{title}{
text
}
\lembox{title}{text}
\end{document}

which produce:

enter image description here

How can I improve my code to produce the same images

Best Answer

Some code to start working. It mixes tcolorbox for lemmas and chapter title and tikzpictures for sections. Some comments before adopting it. I don't know how to pass parameters to titleformat then title box additions are fixed inside chapter style. These additions are made one with title option and date with a overlayed node. They have different format which you should correct. I didn't adjusted lines between tikz and tcolorbox, therefore, section's lines and lemmas and chapter frames are different. You should also adjust them.

enter image description here

\documentclass{report}
\usepackage[most]{tcolorbox}
\usepackage{lmodern}
\usepackage{lipsum}
\usepackage[explicit]{titlesec}
\usepackage{varwidth}

\tcbset{
    orange/.style={
        enhanced,
        colback=orange!10,
        colframe=orange,
        fonttitle=\bfseries,
        colbacktitle=orange!40,
        coltitle=black,
        attach boxed title to top left={%
            yshift*=-\tcboxedtitleheight/2, 
            xshift=5mm},
        boxed title style={colframe=gray}
    }
}

\newtcbtheorem[auto counter]{mylemma}{Lemma}{%
    orange
    }{lm}

\titleformat{\chapter}[display]
  {\normalfont\Large\bfseries}
  {}
  {}
  {%
    \begin{tcolorbox}[orange, halign=center, valign=center, title=test, overlay={\node[draw=gray, fill=orange!40, rounded corners, anchor=east, font=\small\bfseries] at ([xshift=-5mm]frame.south east){2016-2017};}]%, title=Title]
    #1
   \end{tcolorbox}%
  }

\titleformat{\section}
  {\normalfont\large\bfseries}{}{0em}
  {%
    \setbox0=\hbox{\large\bfseries\thesection}%
    \begin{tikzpicture}
        \draw[orange, ultra thick](0,0) -- ++(0:\linewidth);
        \node[draw=orange,
        rounded corners,
        fill=orange!10,
        ultra thick,
        anchor=west,
        outer sep=0pt
        ] {\thesection\hspace{.5em}\hangindent\wd0\strut#1\strut};
    \end{tikzpicture}%
  }

\titleformat{name=\section,numberless}[display]
  {\normalfont\Large\bfseries}{}{0em}
  {%
    \begin{tikzpicture}
        \draw[orange, line width=1mm](0,0) -- ++(0:\linewidth);
        \node[draw=orange,
        rounded corners,
        fill=orange!10,
        line width=1mm,
        anchor=west,
        outer sep=0pt
        ] {\strut#1\strut};
    \end{tikzpicture}%
  }
\titlespacing*{\section}
  {0pt}{4.5ex plus 1ex minus .2ex}{1ex plus .2ex}

\begin{document}

\chapter*{Diagonalizar matrices}
\section{Test numbered section}
\begin{mylemma}{Test}{a}
\lipsum[3]
\end{mylemma}

\begin{mylemma}{Test}{a}
\lipsum[3]
\end{mylemma}

\section*{Test unnumbered section}
\lipsum[4]
%\section{Test numbered section with a long title; in fact, it spans two lines}
%\lipsum[4]

\end{document}

I've taken some ideas from Gonzalo's answers to chapter style with tcolorbox? and Symbol or image behind heading

Related Question