7

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

Educ
  • 4,362
  • 1
    This is alreadyavailable in tcolorbox? What is the actual question? – percusse May 11 '18 at 15:02
  • Where ? is there chapter style in tcolorbox with the same section styles – Educ May 11 '18 at 15:13
  • @percusse I checked this link ftp://ftp.di.uminho.pt/pub/ctan/info/latex-samples/MemoirChapStyles/MemoirChapStyles.pdf but with no luck – Educ May 11 '18 at 16:31

2 Answers2

8

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

Ignasi
  • 136,588
  • Can I ask new question I would like to add new agrument to tcolorbox to be able to change '2016-2017' – Educ May 15 '18 at 10:08
  • @Educ I don't know with arguments, but you can replace 2016-2017 by a macro in \titleformat (let's say \setyear) and change the value for this macro whenever you want (\def\setyear{2017-2018}). – Ignasi May 15 '18 at 12:03
  • what do you suggest for the title's name – Educ May 15 '18 at 12:27
  • @Educ what's wrong with another macro? – Ignasi May 15 '18 at 19:34
5

Something like this?

\documentclass[12pt,a4paper]{report}
\usepackage{lipsum}
\usepackage[explicit]{titlesec}
\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 xsep=5mm, inner ysep=10mm]
\tikzstyle{b} = [rectangle,draw,rounded corners=2mm,line width=.5pt,fill=orange!25,minimum height=0mm,align=left,inner sep=2mm,font=\bfseries]
\tikzstyle{c} = [rectangle,draw,rounded corners=2mm,draw=orange,line width=.5pt,fill=orange!5,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}
}
\def\chapbox#1{%
\begin{tikzpicture}
\draw[orange] (0,0) -- (\textwidth,0);
\node[right,c] (0,0){\thechapter{} -- #1};
\end{tikzpicture}
}
\def\secbox#1{%
\begin{tikzpicture}
\draw[orange,line width=.5pt] (0,0) -- (\textwidth,0);
\node[right,c] (0,0){\thesection{} -- #1};
\end{tikzpicture}
}
\parindent=0mm
\titleformat{\section}
{\normalfont}{}{0em}
{\secbox{#1}}
\titleformat{\chapter}
{\normalfont}{}{0em}
{\chapbox{#1}}
\begin{document}
\titlebox{title}{
blablabla
}
\chapter{First chapter}
\lipsum[1]
\section{First section}
\lembox{title}{text}
\lipsum[2]
\section{Second section}
\lipsum[3]
\lembox{title}{text}
\lipsum[4]
\end{document}

You can modify the chapter and section through titlesec, Including the fact that by default the chapter starts in a new page.

gvgramazio
  • 2,660
  • Thank you but for chapter should boxed like you did in Titlebox – Educ May 11 '18 at 16:05
  • then in the definition of chapter with titlesec simply call titlebox instad of chapbox or rewrite chap box as a title box. Anyway don't use this answer nor your mwe. just use tcolorbox. I didn't know of that package – gvgramazio May 11 '18 at 16:12
  • Is there package for that ? – Educ May 11 '18 at 16:17
  • 1
    Yeah...tcolorbox, this is the documentation http://ctan.mirror.garr.it/mirrors/CTAN/macros/latex/contrib/tcolorbox/tcolorbox.pdf – gvgramazio May 11 '18 at 17:24
  • I changed the chapbox with titlebox but I can't write inside the box of chapter – Educ May 11 '18 at 20:22