10

I would like to create a boxes for

  • theorem
  • definition
  • proposition

to looks like the following image ( but with counter for each box ) :

enter image description here

I tired with tcolorbox

Here's my code:

%this is created by Mohcine 
\documentclass[10pt,a4paper]{report}
\usepackage[margin=1in]{geometry}
\usepackage{amsthm,amssymb,amsfonts}
\usepackage{tikz,lipsum,lmodern}
\usepackage[most]{tcolorbox}


\newtcolorbox{Box1}[2][]{
                lower separated=false,
                colback=white!80!gray,
colframe=white, fonttitle=\bfseries,
colbacktitle=white!50!gray,
coltitle=black,
enhanced,
attach boxed title to top left={xshift=0.5cm,yshift=-2mm},
title=#2,#1}


\newtcolorbox{Box2}[2][]{
                lower separated=false,
                colback=white,
colframe=black,fonttitle=\bfseries,
colbacktitle=black,
coltitle=white,
enhanced,
attach boxed title to top left={yshift=-0.1in,xshift=0.15in},
                 boxed title style={boxrule=0pt,colframe=white,},
title=#2,#1}

\newtcolorbox{Box3}[2][]{
                lower separated=false,
                colback=white!80!gray,
colframe=white!20!black,fonttitle=\bfseries,
colbacktitle=white!30!gray,
coltitle=black,
enhanced,
attach boxed title to top left={xshift=0.5cm,
        yshift=-2mm},
title=#2,#1}

\newtcolorbox{Box4}[2][]{arc=0mm,
                lower separated=false,
                colback=white!30!gray,
colframe=white!20!black,fonttitle=\bfseries,
colbacktitle=white!30!gray,
coltitle=black,
enhanced,
attach boxed title to top left={xshift=0.5cm,
        yshift=-2mm},
title=#2,#1}

\begin{document}

\begin{Box1}{Définition}
  Soit $X : \Omega \longrightarrow E$ une variable aléatoire. On appelle loi de $X$ l'application
    \[ P_{X} : X\left( \Omega \right)\to  [0,1],\quad x\mapsto \mathbb{P}\left( X=x\right)\]
\end{Box1}

\begin{Box2}{Proposition: Loi image}
 Soit $X : \Omega \longrightarrow E$  une variable aléatoire et $f : E \longrightarrow F$ . La loi de la variable aléatoire $Y=f\circ  X$
est donnée par
\[\forall y \in f\left(X\left(\Omega \right) \right),\quad \mathbb{P}\left(Y=y\right)=\sum_{x\in f^{-1}\left(\{y\} \right)}\mathbb{P}\left(X=x \right).  \]
\end{Box2}

\begin{Box4}{}
\begin{center}
{\Huge\textbf{Les méthodes à maitriser}}
\end{center}
\end{Box4}

\begin{Box3}{Méthode 26.1 : Savoir calculer la loi d'une variable aléatoire}
Il faut tout d'abord déterminer l'ensemble A des valeurs possibles de $X$, puis de calculer les
$\mathbb{P}\left(X=x\right)$, $x$ parcourant l'ensemble des valeurs prises par $X$. On représente généralement le résultat sous forme de tableau
\end{Box3}

\end{document}

Which produces :

enter image description here

  • why not using \tcbnewtheorem etc? – user31729 Feb 24 '17 at 10:49
  • i don't know but could make the same style ? – Educ Feb 24 '17 at 10:50
  • I have removed the mdframed tag since that package is not used here – user31729 Feb 24 '17 at 11:11
  • of course no problem, Good texifying. – Educ Feb 24 '17 at 11:13
12

I suggest the usage of \newtcbtheorem -- it is configurable with options like any other tcolorbox environment, the title content is used from the 2nd argument. The 3rd. argument is meant for the label and can be left empty if not needed.

By using auto counter each theorem defines a 'personal' counter, with number within=.. there's fine control on the numbering style.

The general syntax of a \newtcbtheorem definition is

\newtcbtheorem[init options]{theoremenvname}{Theorem Name}{options}{prefix}

where prefix is prepended to a possible label, i.e. if the prefix is def the label for foo would be def:foo, \newtcbtheorem uses a pre-defined label separator :, but this can be changed with the option label separator=...

The example for method environment shows how to specify the options.

Edit: tcolorbox theorem numbering is a related question.

%this is created by Mohcine 
\documentclass[10pt,a4paper]{report}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage[margin=1in]{geometry}
\usepackage{amsthm,amssymb,amsfonts}
\usepackage{tikz,lipsum,lmodern}
\usepackage[most]{tcolorbox}


\newtcbtheorem[auto counter]{definition}{Définition}{
                lower separated=false,
                colback=white!80!gray,
colframe=white, fonttitle=\bfseries,
colbacktitle=white!50!gray,
coltitle=black,
enhanced,
boxed title style={colframe=black},
attach boxed title to top left={xshift=0.5cm,yshift=-2mm},
}{def}


\newtcbtheorem[auto counter]{proposition}{Proposition}{%
                lower separated=false,
                colback=white,
colframe=black,fonttitle=\bfseries,
colbacktitle=black,
coltitle=white,
enhanced,
attach boxed title to top left={yshift=-0.1in,xshift=0.15in},
                 boxed title style={boxrule=0pt,colframe=white,},
}{prop}

\newtcbtheorem[auto counter,number within=chapter]{method}{Méthode}{%
                lower separated=false,
                colback=white!80!gray,
colframe=white!20!black,fonttitle=\bfseries,
colbacktitle=white!30!gray,
coltitle=black,
enhanced,
attach boxed title to top left={xshift=0.5cm,
        yshift=-2mm},
}{met}

\newtcolorbox{Box4}[2][]{arc=0mm,
                lower separated=false,
                colback=white!30!gray,
colframe=white!20!black,fonttitle=\bfseries,
colbacktitle=white!30!gray,
coltitle=black,
enhanced,
attach boxed title to top left={xshift=0.5cm,
        yshift=-2mm},
title=#2,#1}

\begin{document}

\begin{definition}{}{}
  Soit $X : \Omega \longrightarrow E$ une variable aléatoire. On appelle loi de $X$ l'application
    \[ P_{X} : X\left( \Omega \right)\to  [0,1],\quad x\mapsto \mathbb{P}\left( X=x\right)\]
\end{definition}

\begin{proposition}{Loi image}{}
 Soit $X : \Omega \longrightarrow E$  une variable aléatoire et $f : E \longrightarrow F$ . La loi de la variable aléatoire $Y=f\circ  X$
est donnée par
\[\forall y \in f\left(X\left(\Omega \right) \right),\quad \mathbb{P}\left(Y=y\right)=\sum_{x\in f^{-1}\left(\{y\} \right)}\mathbb{P}\left(X=x \right).  \]
\end{proposition}

\begin{Box4}{}
\begin{center}
{\Huge\textbf{Les méthodes à maitriser}}
\end{center}
\end{Box4}

\setcounter{chapter}{26}

\begin{method}[colbacktitle={yellow}]{Savoir calculer la loi d'une variable aléatoire}{}
Il faut tout d'abord déterminer l'ensemble A des valeurs possibles de $X$, puis de calculer les
$\mathbb{P}\left(X=x\right)$, $x$ parcourant l'ensemble des valeurs prises par $X$. On représente généralement le résultat sous forme de tableau
\end{method}

\end{document}

enter image description here

  • 1
    @Educ: You're welcome. I've added the boxed title style={colframe=black} option to definition box -- it was missing (and is not shown in the screenshot) – user31729 Feb 24 '17 at 11:06
  • @ChristianHupfer I have voted your answer and it is useful to regard even my question of my little book that I will present at the university. But Définition 1 borderless was better :-). – Sebastiano Feb 24 '17 at 11:58
  • @Sebastiano: Well better or worse is opinion - based. Nobody is forced to do so. And actually, all is stated in the tcolorbox manual – user31729 Feb 24 '17 at 12:00
  • @ChristianHupfer I hope you did not get angry. – Sebastiano Feb 24 '17 at 12:03
5

Here's a solution just using counters incremented before the title. I would advice you to prefix the counter value with your title setup (e.g. "Definition") per box so you do not have to type it every time.

%this is created by Mohcine 
\documentclass[10pt,a4paper]{report}
\usepackage[margin=1in]{geometry}
\usepackage{amsthm,amssymb,amsfonts}
\usepackage{tikz,lipsum,lmodern}
\usepackage[most]{tcolorbox}

\newcounter{mbo}
\newcounter{mbt}
\newcounter{mbth}

\newtcolorbox{Box1}[2][]{
            before title={\stepcounter{mbo}},
                lower separated=false,
                colback=white!80!gray,
colframe=white, fonttitle=\bfseries,
colbacktitle=white!50!gray,
coltitle=black,
enhanced,
attach boxed title to top left={xshift=0.5cm,yshift=-2mm},
title={\thembo~#2},#1}


\newtcolorbox{Box2}[2][]{
            before title={\stepcounter{mbt}},
                lower separated=false,
                colback=white,
colframe=black,fonttitle=\bfseries,
colbacktitle=black,
coltitle=white,
enhanced,
attach boxed title to top left={yshift=-0.1in,xshift=0.15in},
                 boxed title style={boxrule=0pt,colframe=white,},
title={\thembt~#2},#1}

\newtcolorbox{Box3}[2][]{
            before title={\stepcounter{mbth}},
                lower separated=false,
                colback=white!80!gray,
colframe=white!20!black,fonttitle=\bfseries,
colbacktitle=white!30!gray,
coltitle=black,
enhanced,
attach boxed title to top left={xshift=0.5cm,
        yshift=-2mm},
title={\thembth~#2},#1}

\newtcolorbox{Box4}[2][]{arc=0mm,
                lower separated=false,
                colback=white!30!gray,
colframe=white!20!black,fonttitle=\bfseries,
colbacktitle=white!30!gray,
coltitle=black,
enhanced,
attach boxed title to top left={xshift=0.5cm,
        yshift=-2mm},
title=#2,#1}

\begin{document}

\begin{Box1}{Définition}
  Soit $X : \Omega \longrightarrow E$ une variable aléatoire. On appelle loi de $X$ l'application
    \[ P_{X} : X\left( \Omega \right)\to  [0,1],\quad x\mapsto \mathbb{P}\left( X=x\right)\]
\end{Box1}

\begin{Box2}{Proposition: Loi image}
 Soit $X : \Omega \longrightarrow E$  une variable aléatoire et $f : E \longrightarrow F$ . La loi de la variable aléatoire $Y=f\circ  X$
est donnée par
\[\forall y \in f\left(X\left(\Omega \right) \right),\quad \mathbb{P}\left(Y=y\right)=\sum_{x\in f^{-1}\left(\{y\} \right)}\mathbb{P}\left(X=x \right).  \]
\end{Box2}

\begin{Box4}{}
\begin{center}
{\Huge\textbf{Les méthodes à maitriser}}
\end{center}
\end{Box4}

\begin{Box3}{Méthode 26.1 : Savoir calculer la loi d'une variable aléatoire}
Il faut tout d'abord déterminer l'ensemble A des valeurs possibles de $X$, puis de calculer les
$\mathbb{P}\left(X=x\right)$, $x$ parcourant l'ensemble des valeurs prises par $X$. On représente généralement le résultat sous forme de tableau
\end{Box3}

\end{document}
  • +1 thank you but i prefer solution of Christian Hupfer – Educ Feb 24 '17 at 11:05

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.