1

I'm working on remaking a custom class for my lessons. I had an old one using TikZ that allowed me to have this behavior:

enter image description here

But it was buggy and did not allow for breakable environments.

I am now trying to remake everything using tcolorbox but the code I found produces this:

enter image description here

Here is the code I'm using:

\newlength{\mylen}
\newlength{\hauteur}
\settowidth{\mylen}{Méthode}
\setlength{\hauteur}{\baselineskip}
\addtolength{\hauteur}{0.5mm}

\newtcbtheorem{methode}{Méthode :}{
    enhanced,
    breakable,
    coltitle=eggplant, fonttitle=\bfseries, 
    detach title,
    opacityfill=0,
    frame hidden,
    %left=\dimexpr\textwidth-\mylen\relax,
    %top=0mm,
    %boxsep=0mm,
    borderline west = {0.5pt}{0pt}{},
    overlay unbroken and first={
        \node[xshift=-\mylen,yshift=-\hauteur] at (frame.north west) {\tcbtitle};
    }
}{meth}

The sidebyside option could work but it does not allow breakable environments, could someone point me in the right direction?

Edit : As asked here is some compilable code :

\documentclass[a4paper,oneside]{extreport}

\usepackage{fullpage}

\usepackage[svgnames]{xcolor}

\usepackage{arev}

\usepackage[french]{babel}

\usepackage{tcolorbox}
\tcbuselibrary{most}

\newlength{\mylen}
\newlength{\hauteur}
\newlength{\malongueur}
\settowidth{\mylen}{Méthode :}
\setlength{\hauteur}{\baselineskip}
\addtolength{\hauteur}{0.5mm}
\settowidth{\malongueur}{408.52pt}
%\addtolength{\malongueur}{-\mylen}

%définition des couleurs
\definecolor{blueslategray}{cmyk}{0.189, 0.091, 0, 0.439}
\definecolor{greenbrown}{HTML}{555544}
\definecolor{cottonseed}{cmyk}{0, 0.026, 0.047, 0.255}
\definecolor{lightblue}{cmyk}{0.272, 0.068, 0, 0.192}
\definecolor{bluetrout}{cmyk}{0.18, 0.15, 0, 0.608}
\definecolor{brownred}{cmyk}{0, 0.531, 0.557, 0.239}
\definecolor{orangewhite}{cmyk}{0, 0.031, 0.075, 0.004}
\definecolor{avocado}{cmyk}{0.06, 0, 0.55, 0.37}
\definecolor{eggplant}{cmyk}{0.04, 0.24, 0, 0.47}
\definecolor{darkblue}{rgb}{0.12,0.47,0.87}

\newtcbtheorem{theoreme}{Théorème}{
    lower separated=false,
    colback=orangewhite,
    colframe=white, fonttitle=\bfseries,
    colbacktitle=brownred,
    coltitle=orangewhite,
    coltext=brownred,
    enhanced,
    breakable,
    boxed title style={colframe=greenbrown},
    attach boxed title to top left={yshift=-2mm},
}{theo}

\newtcbtheorem{methode}{Méthode :}{%
    enhanced,
    breakable,
    coltitle=eggplant, fonttitle=\bfseries, 
    detach title,
    opacityfill=0,
    frame hidden,
    %left=30mm,
    %top=0mm,
    %boxsep=0mm,
    borderline west = {0.5pt}{0pt}{},
    overlay unbroken and first={
        \node[xshift=-\mylen,yshift=-\hauteur] at (frame.north west) {\tcbtitle};
    }
}{meth}

\begin{document}
\begin{theoreme}{}{}
    du texte \textbf{texte} \dotfill
\end{theoreme}

\begin{methode*}{}{}
    du texte
\end{methode*}
\end{document}

Here is a 'working' version :

\documentclass[a4paper,oneside]{extreport}

\usepackage{fullpage}

\usepackage[svgnames]{xcolor}

\usepackage{arev}

\usepackage[french]{babel}
\usepackage{lipsum}
\usepackage{tcolorbox}
\tcbuselibrary{most}

\newlength{\mylen}
\newlength{\hauteur}
\newlength{\malongueur}
\settowidth{\mylen}{Méthode :}
\setlength{\hauteur}{\baselineskip}
\addtolength{\hauteur}{0.5mm}
\settowidth{\malongueur}{408.52pt}
%\addtolength{\malongueur}{-\mylen}

%définition des couleurs
\definecolor{blueslategray}{cmyk}{0.189, 0.091, 0, 0.439}
\definecolor{greenbrown}{HTML}{555544}
\definecolor{cottonseed}{cmyk}{0, 0.026, 0.047, 0.255}
\definecolor{lightblue}{cmyk}{0.272, 0.068, 0, 0.192}
\definecolor{bluetrout}{cmyk}{0.18, 0.15, 0, 0.608}
\definecolor{brownred}{cmyk}{0, 0.531, 0.557, 0.239}
\definecolor{orangewhite}{cmyk}{0, 0.031, 0.075, 0.004}
\definecolor{avocado}{cmyk}{0.06, 0, 0.55, 0.37}
\definecolor{eggplant}{cmyk}{0.04, 0.24, 0, 0.47}
\definecolor{darkblue}{rgb}{0.12,0.47,0.87}

\newtcbtheorem{theoreme}{Théorème}{
    lower separated=false,
    colback=orangewhite,
    colframe=white, fonttitle=\bfseries,
    colbacktitle=brownred,
    coltitle=orangewhite,
    coltext=brownred,
    enhanced,
    breakable,
    boxed title style={colframe=greenbrown},
    attach boxed title to top left={yshift=-2mm},
}{theo}

\newtcbtheorem{methode}{Méthode :}{%
    enhanced,
    breakable,
    coltitle=eggplant, fonttitle=\bfseries, 
    colbacktitle=white,
    detach title,
    opacityfill=0,
    frame hidden,
    left skip=1.55\mylen,
    left=0mm,
    top=0.3mm,
    toptitle=0mm,
    %boxsep=0mm,
    %attach boxed title to top left,
    %borderline west = {0.5pt}{0pt}{},
     overlay unbroken and first={
         \node[below left] at (interior.north west) {\tcbtitle};
     }
}{meth}

\newtcbtheorem{exemple}{Exemple :}{%
    enhanced,
    breakable,
    coltitle=eggplant, fonttitle=\bfseries, 
    colbacktitle=white,
    detach title,
    opacityfill=0,
    frame hidden,
    left skip=1.55\mylen,
    left=0mm,
    top=0.3mm,
    toptitle=0mm,
    %boxsep=0mm,
    %attach boxed title to top left,
    %borderline west = {0.5pt}{0pt}{},
     overlay unbroken and first={
         \node[below left] at (interior.north west) {\tcbtitle};
     }
}{exemp}

\begin{document}

\begin{theoreme}{}{}
dsds\dotfill
\end{theoreme}

\begin{methode*}{}{}
fkdlsmfkdlsm \dotfill
\lipsum
\end{methode*}

\begin{exemple*}{}{}
turlututu \lipsum
\end{exemple*}

\end{document}
  • 1
    Please give a fully compilable code. – AndréC Aug 3 at 9:52
  • I put some compilable code in the original post. – Guillaume Largillier Aug 3 at 10:33
  • As I understand it, the method box doesn't have to fit in the margin, right? It's from the lengths you add \mylen and \hauteur and \malongueur. Delete that. – AndréC Aug 3 at 11:16
  • Do you insist on having the vertical rule in "second box"? IMHO it doesnt provide the nicest look and puts you in wrong direction (side-by-side boxes). If you dismiss that, you are actually almost done. – Tomáš Kruliš Aug 3 at 11:16
  • Ok I feel like I'm on the right way, I found out about left shift, the question would be to find the best way to compute the shifting values ans width values of the box so that everything stays coherent throughout the document. – Guillaume Largillier Aug 3 at 11:25
1

Following code shows some modifications to OP's code to obtain a result more similar to original image.

Now Theorem environment has sharp corners, title attached without overlapping with text contents and border lines in right side and bottom.

In example, the overlay part has been modified to introduce the vertical line between title and contents. Similar solution could be applied to methode environment.

\documentclass[a4paper,oneside]{extreport}

\usepackage{fullpage}

\usepackage[svgnames]{xcolor}

\usepackage{arev}

\usepackage[french]{babel}
\usepackage{lipsum}
\usepackage{tcolorbox}
\tcbuselibrary{most}

\newlength{\mylen}
\newlength{\hauteur}
\newlength{\malongueur}
\settowidth{\mylen}{Méthode :}
\setlength{\hauteur}{\baselineskip}
\addtolength{\hauteur}{0.5mm}
\settowidth{\malongueur}{408.52pt}
%\addtolength{\malongueur}{-\mylen}

%définition des couleurs
\definecolor{blueslategray}{cmyk}{0.189, 0.091, 0, 0.439}
\definecolor{greenbrown}{HTML}{555544}
\definecolor{cottonseed}{cmyk}{0, 0.026, 0.047, 0.255}
\definecolor{lightblue}{cmyk}{0.272, 0.068, 0, 0.192}
\definecolor{bluetrout}{cmyk}{0.18, 0.15, 0, 0.608}
\definecolor{brownred}{cmyk}{0, 0.531, 0.557, 0.239}
\definecolor{orangewhite}{cmyk}{0, 0.031, 0.075, 0.004}
\definecolor{avocado}{cmyk}{0.06, 0, 0.55, 0.37}
\definecolor{eggplant}{cmyk}{0.04, 0.24, 0, 0.47}
\definecolor{darkblue}{rgb}{0.12,0.47,0.87}

\newtcbtheorem{theoreme}{Théorème}{
    lower separated=false,
    sharp corners,
    colback=orangewhite,
    colframe=brownred, 
    leftrule=0pt, toprule=0pt,
    fonttitle=\bfseries,
    colbacktitle=brownred,
    coltitle=orangewhite,
    coltext=brownred,
    enhanced,
    breakable,
    boxed title style={colframe=brownred, sharp corners},
    attach boxed title to top left,
}{theo}

\newtcbtheorem{methode}{Méthode :}{%
    enhanced,
    breakable,
    coltitle=eggplant, fonttitle=\bfseries, 
    colbacktitle=white,
    detach title,
    opacityfill=0,
    frame hidden,
    left skip=1.55\mylen,
    left=0mm,
    top=0.3mm,
    toptitle=0mm,
    %boxsep=0mm,
    %attach boxed title to top left,
    %borderline west = {0.5pt}{0pt}{},
     overlay unbroken and first={
         \node[below left] at (interior.north west) {\tcbtitle};
     }
}{meth}

\newtcbtheorem{exemple}{Exemple :}{%
    enhanced,
    breakable,
    coltitle=eggplant, fonttitle=\bfseries, 
    colbacktitle=white,
    detach title,
    opacityfill=0,
    frame hidden,
    left skip=1.55\mylen,
    left=0mm,
    top=0.3mm,
    toptitle=0mm,
    %boxsep=0mm,
    %attach boxed title to top left,
    %borderline west = {0.5pt}{0pt}{},
     overlay unbroken and first={
         \node[below left] at (interior.north west) {\tcbtitle};
         \draw[eggplant, line width=1.5pt] (interior.north west)--(interior.south west);
     },
     overlay middle and last={
         \draw[eggplant, line width=1.5pt] (interior.north west)--(interior.south west);
     }
}{exemp}

\begin{document}

\begin{theoreme}{}{}
dsds\dotfill
\end{theoreme}

\begin{methode*}{}{}
fkdlsmfkdlsm \dotfill
\lipsum
\end{methode*}

\begin{exemple*}{}{}
turlututu \lipsum
\end{exemple*}

\end{document}

enter image description here

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.