2

I'm trying to create these environments but without much success ... I wonder if it will be better to create it with tikz or if it is easier to customize the title of a tcolorbox and rotate it a bit ?

Env 1 Env 2

\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage{tikz,tikzpagenodes}
\usepackage[most]{tcolorbox}
\usetikzlibrary{calc}
\usetikzlibrary{intersections, patterns}
\tcbuselibrary{skins}
\usepackage{lipsum}
\usepackage{xcolor,etoolbox}


\definecolor{lightblue}{RGB}{199,232,250}
\definecolor{darkblue}{RGB}{59,134,215}

\begin{document}



\begin{tikzpicture}[overlay,remember picture]
    % container 
    \draw[fill=darkblue,draw=none] (0,0) -- ++(5cm,0) -- ++(0,1cm)
    arc (0:90:0.5) -- ++(-4.5cm,0) -- cycle;
    % Horizontal line 
    \draw[darkblue, line width=2pt] (0,0) -- (\textwidth,0);
    % title of container 
    \node[scale=1.2] at (0.2cm,0.2cm)  {\textcolor{white}{Environment
        Title }};
  \end{tikzpicture}


\end{document}

%%% Local Variables: 
%%% mode: latex
%%% TeX-master: t
%%% End: 
  • 3
    tcolorbox allows title overlays, so that would be a good start. In general tcolorbox is very versatile while every own TikZ solution will be very restricted (of course depending on your needs). – TeXnician Sep 24 '18 at 8:48
2

I propose an other answer quite similar to the one given by @Ignasi but not exactly the same:

(reedited with the improvement proposed by @TeXnician related to the vertical shift of the top line)

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage[most]{tcolorbox}
\usetikzlibrary{calc}
\tcbuselibrary{skins}
\usepackage{xcolor}


\definecolor{titleboxcolor}{RGB}{199,232,250}
\definecolor{darkblue}{RGB}{59,134,215}

\newcommand{\titlepath}{
  \fill[titleboxcolor]
  (title.south east)
  --(title.east)coordinate(A)
  to[curve to,out=90,in=0]($(A)+(-5mm,5mm)$)
      --($(title.north west)+(5mm,0mm)$)coordinate(B)
to[curve to,out=180,in=90]($(B)+(-5mm,-5mm)$)coordinate(C)
      --($(C)+(0mm,-5mm)$)
      to[curve to,out=90,in=180]($(title.south west)+(+5mm,0mm)$)coordinate(F)
      --cycle;
      \draw[titleboxcolor,ultra thick]
      ([yshift=.5\pgflinewidth]title.south east)--
      ([yshift=.5\pgflinewidth]title.south-|interior.east);
    }


\newtcolorbox{myenvironment}{
  enhanced,
  frame empty,
  title=Exercice résolu,
  colback=white,
  coltitle=red,
  attach boxed title to top left={xshift=-5mm},
  boxed title style={empty},
  underlay boxed title=\titlepath

}

\begin{document}

\begin{myenvironment}
  Soit \(f\) une fonction définie sur ...
\end{myenvironment}



\end{document}

enter image description here

  • Thank you both for your answers, would you have a tutorial on tikz or tcolorbox to start, the official documentation is too long to start ? – Clifford Sep 25 '18 at 3:49
  • Just for the protocol: The usage of \[ and \] in this answer is blatantly wrong. – TeXnician Sep 26 '18 at 6:28
  • 1
    And please remove the vertical offset by using \draw[titleboxcolor,ultra thick]([yshift=.5\pgflinewidth]title.south east)--([yshift=.5\pgflinewidth]title.south-|interior.east); instead of your draw command. – TeXnician Sep 26 '18 at 6:30
  • I don't know why but every square bracket in the code I proposed is prefixed with a backslash. I am not sure if that was (or not) the case when I posted it. I will reedit – Hafid Boukhoulda Sep 26 '18 at 7:09
2

Something to start working:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}

\makeatletter
\newtcolorbox{mybox}[2][]{
        enhanced, 
        breakable,
        sharp corners,
        rounded corners=northwest,
        colback=white,
        colframe=orange!80!black,
        fonttitle=\bfseries\large\sffamily,
        frame hidden,
        title=#2,
        attach boxed title to top left,
        boxed title size=standard,
        boxed title style={%
                empty,
                rounded corners=north, 
                boxrule=0pt,
                bottom=0pt,
        },
          underlay boxed title={%
                \filldraw[rounded corners=\kvtcb@arc, orange!80!black, line width=.5mm]
                    (title.south east)--++(93:\tcboxedtitleheight)--++(183:\tcboxedtitlewidth)--++(-87:\tcboxedtitleheight)|-cycle;
                \draw[tcbcolframe, line width=.5mm] (title.south)|-(frame.north east);
                },
        #1
    }
\makeatother

\begin{document}
\begin{mybox}{Exercice résolu}
\lipsum[2]
\end{mybox}

\end{document}

enter image description here

Note Previous code has been updated for compatibility with tcolorbox v4.20. If you're using previous versions, rename colors with form tcbcol... to older form tcbcol@....

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.