-1

so I didn't want to do a duplicate but apparently I can't know the answer on my previous post...

so the original question was here : tcolorbox use for theorems

and now I ve done this:

it solves my problems. Can I ask you how to modify one part of the code ?

So with this question :How make framed blocks in beamer I have create the box theoreme. But I d like to write the name of the theorem in the small upper box. How can I add this :)?

\documentclass{article}
\usepackage{lipsum}
\usepackage{amsmath,amssymb}
\usepackage[most]{tcolorbox}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{lmodern}
\usepackage{xcolor}

\definecolor{vert}{RGB}{0,181,0}
\definecolor{oran}{RGB}{223,74,0}
\definecolor{viol}{RGB}{134,0,175}
\definecolor{roug}{RGB}{215,15,0}



\newtcolorbox[auto counter]{theoreme}[1]{%
    colback=white,
    colframe=roug,
    colbacktitle=white!90!roug,
    coltitle=black,
    fonttitle=\bfseries, 
    title=Théorème~\thetcbcounter .,
    enhanced,
    attach boxed title to top left={yshift=-2mm, xshift=0.5cm}
}





\tcbset{
    thmbox/.style={
        enhanced,
        breakable,
        sharp corners=all,
        fonttitle=\bfseries\normalsize,
        fontupper=\normalsize\itshape,
         top=0mm,
         bottom=0mm,
         right=0mm,
        colback=white,
        colframe=white,
        colbacktitle=white,
        %coltitle=red,
        attach boxed title to top left,
        boxed title style={empty, size=minimal, bottom=1.5mm},
        overlay unbroken ={
            \draw (title.south west)--(title.south east);
            \draw ([xshift=3.5mm]frame.north west)|-%
                  (frame.south east)--(frame.north east);},
        overlay first={
            \draw (title.south west)--(title.south east); 
            \draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);
            \draw (frame.north east)--(frame.south east);},
        overlay middle={
            \draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);
            \draw (frame.north east)--(frame.south east);},
        overlay last={
            \draw ([xshift=3.5mm]frame.north west)|-%
                  (frame.south east)--(frame.north east);},
        },
    SV/.style={thmbox, coltitle=vert,
        overlay unbroken ={
            \draw[vert][thick] (title.south west)--(title.south east);
            \draw[vert][thick] ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
        overlay first={
            \draw[vert][thick] (title.south west)--(title.south east); 
            \draw[vert][thick] ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
        overlay middle={
            \draw[vert][thick] ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
        overlay last={
            \draw[vert][thick] ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
        },
    SO/.style={thmbox, coltitle=oran,
        overlay unbroken ={
            \draw[oran][thick] (title.south west)--(title.south east);
            \draw[oran][thick] ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
        overlay first={
            \draw[oran][thick] (title.south west)--(title.south east); 
            \draw[oran][thick] ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
        overlay middle={
            \draw[oran][thick] ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
        overlay last={
            \draw[oran][thick] ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
        },   
    LQ/.style={thmbox, coltitle=viol,
        overlay unbroken ={
            \draw[viol][thick] (title.south west)--(title.south east);
            \draw[viol][thick] ([xshift=3.5mm]frame.north west)|-([xshift=15mm]frame.south west);
            \node[anchor=east] at (frame.south east) {$\square$};},
        overlay first={
            \draw[viol][thick] (title.south west)--(title.south east); 
            \draw[viol][thick] ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
        overlay middle={
            \draw[viol][thick] ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
        overlay last={
            \draw[viol][thick] ([xshift=3.5mm]frame.north west)|-([xshift=15mm]frame.south west);
            \node[anchor=east] at (frame.south east) {$\square$};},
    },  
}


\newtcbtheorem[]{ajoutationV}{Exemple}{thmbox,SV}{theo}
\newtcbtheorem[]{ajoutationO}{Exercice}{thmbox,SO}{theo}
\newtcbtheorem[]{demo}{Démonstration}{thmbox,LQ}{theo}


\begin{document}



\begin{ajoutationV}{}{}
\lipsum[2]
\end{ajoutationV}


\begin{ajoutationO}{}{}
\lipsum[2]
\end{ajoutationO}


\begin{demo}{}{}
\lipsum[1]
\end{demo}



\begin{theoreme}
WOW

\end{theoreme}




\end{document}

I have another problem. I want to define a counter but I don't know how to reset it at the end of each chapter. Any idea?

4
  • A side note: It looks like that, for some reason, your theoreme environment is eating the first character inside it... Jan 24, 2018 at 22:58
  • yes... I don't know why :/ Jan 24, 2018 at 23:11
  • 2
    Your other problem is totally unrelated to this question (please do not ask for multiple issues in one post!), but \newcounter{foo}[chapter] defines a counter named foo in your document. However, your document above uses the article class which does not provide chapters
    – user31729
    Jan 25, 2018 at 6:53
  • yes? :) I ve seen it but the aim is writting this code in a book where chapter are defined... you are saying that \newcounter{foo}[chapter] would work in a book? Jan 25, 2018 at 9:20

1 Answer 1

3

The name of the theorem is written in the small attached box already, but the tcolorbox theoreme is defined with one mandatory argument, so it expects one argument -- if this is not given, it will gobble the first token inside of the environment, WOW becomes OW then.

I suggest to write

\newtcolorbox[auto counter]{theoreme}[2][]{%

instead, in this case the first argument is optional and can be used to change the options of the box. If it is omitted, no harm is done, the second argument is mandatory and meant for the title:

\documentclass{article}
\usepackage{lipsum}
\usepackage{amsmath,amssymb}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[most]{tcolorbox}
\usepackage{lmodern}
\usepackage{xcolor}

\definecolor{vert}{RGB}{0,181,0}
\definecolor{oran}{RGB}{223,74,0}
\definecolor{viol}{RGB}{134,0,175}
\definecolor{roug}{RGB}{215,15,0}



\newtcolorbox[auto counter]{theoreme}[2][]{%
    colback=white,
    colframe=roug,
    colbacktitle=white!90!roug,
    coltitle=black,
    fonttitle=\bfseries, 
    title=Théorème~\thetcbcounter.\ #2,
    enhanced,
    attach boxed title to top left={yshift=-2mm, xshift=0.5cm},%
    #1% For possible options
}





\tcbset{
    thmbox/.style={
        enhanced,
        breakable,
        sharp corners=all,
        fonttitle=\bfseries\normalsize,
        fontupper=\normalsize\itshape,
         top=0mm,
         bottom=0mm,
         right=0mm,
        colback=white,
        colframe=white,
        colbacktitle=white,
        %coltitle=red,
        attach boxed title to top left,
        boxed title style={empty, size=minimal, bottom=1.5mm},
        overlay unbroken ={
            \draw (title.south west)--(title.south east);
            \draw ([xshift=3.5mm]frame.north west)|-%
                  (frame.south east)--(frame.north east);},
        overlay first={
            \draw (title.south west)--(title.south east); 
            \draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);
            \draw (frame.north east)--(frame.south east);},
        overlay middle={
            \draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);
            \draw (frame.north east)--(frame.south east);},
        overlay last={
            \draw ([xshift=3.5mm]frame.north west)|-%
                  (frame.south east)--(frame.north east);},
        },
    SV/.style={thmbox, coltitle=vert,
        overlay unbroken ={
            \draw[vert][thick] (title.south west)--(title.south east);
            \draw[vert][thick] ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
        overlay first={
            \draw[vert][thick] (title.south west)--(title.south east); 
            \draw[vert][thick] ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
        overlay middle={
            \draw[vert][thick] ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
        overlay last={
            \draw[vert][thick] ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
        },
    SO/.style={thmbox, coltitle=oran,
        overlay unbroken ={
            \draw[oran][thick] (title.south west)--(title.south east);
            \draw[oran][thick] ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
        overlay first={
            \draw[oran][thick] (title.south west)--(title.south east); 
            \draw[oran][thick] ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
        overlay middle={
            \draw[oran][thick] ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
        overlay last={
            \draw[oran][thick] ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
        },   
    LQ/.style={thmbox, coltitle=viol,
        overlay unbroken ={
            \draw[viol][thick] (title.south west)--(title.south east);
            \draw[viol][thick] ([xshift=3.5mm]frame.north west)|-([xshift=15mm]frame.south west);
            \node[anchor=east] at (frame.south east) {$\square$};},
        overlay first={
            \draw[viol][thick] (title.south west)--(title.south east); 
            \draw[viol][thick] ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
        overlay middle={
            \draw[viol][thick] ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
        overlay last={
            \draw[viol][thick] ([xshift=3.5mm]frame.north west)|-([xshift=15mm]frame.south west);
            \node[anchor=east] at (frame.south east) {$\square$};},
    },  
}


\newtcbtheorem[]{ajoutationV}{Exemple}{thmbox,SV}{theo}
\newtcbtheorem[]{ajoutationO}{Exercice}{thmbox,SO}{theo}
\newtcbtheorem[]{demo}{Démonstration}{thmbox,LQ}{theo}


\begin{document}



\begin{ajoutationV}{}{}
\lipsum[2]
\end{ajoutationV}


\begin{ajoutationO}{}{}
\lipsum[2]
\end{ajoutationO}


\begin{demo}{}{}
\lipsum[1]
\end{demo}



\begin{theoreme}{A nice theorem}
WOW
\end{theoreme}

\end{document}

enter image description here

7
  • so by addind the [] you define a command where a title can be add? and what is the #1? Jan 25, 2018 at 8:39
  • 1
    @MarineGalantin: No, [] is an optional argument which can be omitted, where [2][] would define one with a mandatory argument. You should really read some introduction to LaTeX. And do you want to add some extra title to Theoreme~\thetcbcounter? That is not obvious from your question
    – user31729
    Jan 25, 2018 at 8:42
  • I read but this is not that obvious. I am not really into informatics, always get bad grades in this topic :p I want that the title of the box would be: Theorem {counter} (name_of_theorem) ( there was also the question of how to reset the counter...?) Jan 25, 2018 at 9:01
  • 1
    @MarineGalantin: I added a comment about resetting the counter just below your question
    – user31729
    Jan 25, 2018 at 9:04
  • 1
    @MarineGalantin: And LaTeX is not Quantum Field theory which is really difficult ;-) I've changed the answer
    – user31729
    Jan 25, 2018 at 9:07

Not the answer you're looking for? Browse other questions tagged .