2

I would like to know how to put the text "MyTitle" in argument of the environment and also to place it on the right?

\documentclass[12pt]{article}
\usepackage{lmodern}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\newcounter{mycounter}

\setlength{\parindent}{0pt}

\begin{document}

\tcbset{exercisebox/.style={enhanced,colback=white,colframe=green!65!black,
enlarge top by=10mm,
overlay={%
\path[fill=blue!65,line width=.4mm] (frame.north west)--++(17mm,0)coordinate(n2)--++(0,8mm)--++(-20mm,0) arc (-90:90:-4mm)--cycle;
\node at ([shift={(5mm,4mm)}]frame.north west){\color{white}{\textbf{\sffamily Exercise}}};
\path[fill=green!65!blue] ([xshift=.4mm]n2)--++(0,8mm)--++(7mm,0)--++(0,-8mm)--cycle;
\node at ([shift={(4mm,4mm)}]n2){\color{white}{\textbf{\sffamily \themycounter}}};
\node at ([shift={(18mm,4mm)}]n2){\itshape\textbf{\sffamily MyTitle}};
}}}

Before... 

\begin{tcolorbox}[exercisebox,step=mycounter,label=one]
My exercise here...
\end{tcolorbox}

After...

\end{document}

Thank you !

3
  • Welcome to TeX.SE!! Can you post an image of your exact requirement? Please...
    – MadyYuvi
    Commented Mar 21, 2021 at 13:14
  • Is this the output you want to achieve? i.sstatic.net/FXxjU.png
    – leandriis
    Commented Mar 21, 2021 at 13:18
  • @insan -- the title on the right side implemented on the RHS -- have a look at the answer below
    – js bibra
    Commented Mar 21, 2021 at 13:53

3 Answers 3

2

I guess, the following is closer to the expected output. The title text can be adjusted per box using the title=<your title text here> option:

enter image description here

\documentclass[12pt]{article}
\usepackage{lmodern}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\newcounter{mycounter}

\setlength{\parindent}{0pt}

\begin{document}

\tcbset{exercisebox/.style={
    enhanced,
    colback=white,
    colframe=green!65!black,
    coltitle=black,
    fonttitle =\itshape\bfseries\sffamily,
    boxed title style={
        colback=white,
        colframe=white,
        boxrule=1pt},
    attach boxed title to top right,
    overlay={%
        \path[fill=blue!65,line width=.4mm] (frame.north west)--++(17mm,0)coordinate(n2)--++(0,8mm)--++(-20mm,0) arc (-90:90:-4mm)--cycle;
        \node at ([shift={(5mm,4mm)}]frame.north west){\color{white}{\textbf{\sffamily Exercise}}};
        \path[fill=green!65!blue] ([xshift=.4mm]n2)--++(0,8mm)--++(7mm,0)--++(0,-8mm)--cycle;
    \node at ([shift={(4mm,4mm)}]n2){\color{white}{\textbf{\sffamily \themycounter}}};
    }}}

Before... 

\begin{tcolorbox}[exercisebox,step=mycounter,label=one, title=my title]
My exercise here...
\end{tcolorbox}

After...

\begin{tcolorbox}[exercisebox,step=mycounter,label=one, title=This box gets a different title]
My exercise here...
\end{tcolorbox}

After...

\end{document}
1

This is like leandris solution with some changes.

A new exercise box with auto counter has been declared. It has two parameters, an optional one which can be used to include formatting changes and a mandatory one which is the title. In case of no title, just left the empty brackets.

\documentclass[12pt]{article}
\usepackage{lmodern}
\usepackage{tcolorbox}
\tcbuselibrary{skins}

\setlength{\parindent}{0pt}

\tcbset{exercisebox/.style={
    enhanced,
    colback=white,
    colframe=green!65!black,
    coltitle=black,
    fonttitle =\itshape\bfseries\sffamily,
    boxed title style={
        colback=white,
        colframe=white,
        boxrule=1pt},
    attach boxed title to top right,
    overlay={%
        \path[fill=blue!65,line width=.4mm] (frame.north west)--++(17mm,0)coordinate(n2)--++(0,8mm)--++(-20mm,0) arc (-90:90:-4mm)--cycle;
        \node at ([shift={(5mm,4mm)}]frame.north west){\color{white}{\textbf{\sffamily Exercise}}};
        \path[fill=green!65!blue] ([xshift=.4mm]n2)--++(0,8mm)--++(7mm,0)--++(0,-8mm)--cycle;
    \node at ([shift={(4mm,4mm)}]n2){\color{white}{\textbf{\sffamily \thetcbcounter}}};
    }}}

\newtcolorbox[auto counter]{exercise}[2][]{exercisebox,
title=#2,#1
}
\begin{document}

Before... 

\begin{exercise}{my title}
My exercise here...
\end{exercise}

After...

\begin{exercise}[colback=green!10]{This box gets a different title}
My exercise here...
\end{exercise}

After...

\begin{exercise}[colback=red!10]{}
An exercise without title
\end{exercise}

\end{document}

enter image description here

0

enter image description here

\documentclass[12pt]{article}
\usepackage{lmodern}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\newcounter{mycounter}

\setlength{\parindent}{0pt}

\begin{document}
    
    \tcbset{exercisebox/.style={enhanced,colback=white,colframe=green!65!black,
            enlarge top by=10mm,
            overlay={%
                \path[fill=blue!65,line width=.4mm] (frame.north west)--++(17mm,0)coordinate(n2)--++(0,8mm)--++(-20mm,0) arc (-90:90:-4mm)--cycle;
                \node at ([shift={(5mm,4mm)}]frame.north west){\color{white}{\textbf{\sffamily Exercise}}};
                \path[fill=green!65!blue] ([xshift=.4mm]n2)--++(0,8mm)--++(7mm,0)--++(0,-8mm)--cycle;
                \node at ([shift={(4mm,4mm)}]n2){\color{white}{\textbf{\sffamily \themycounter}}};
                \node at ([shift={(-8mm,4mm)}]frame.north east){\itshape\textbf{\sffamily MyTitle}};
    }}}
    
    Before... 
    
    \begin{tcolorbox}[exercisebox,step=mycounter,label=one]
        My exercise here...
    \end{tcolorbox}
    
    After...
    
\end{document}

OR

enter image description here

\documentclass[12pt]{article}
\usepackage{lmodern}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\newcounter{mycounter}

\setlength{\parindent}{0pt}

\begin{document}
    
    \tcbset{exercisebox/.style={enhanced,colback=white,colframe=green!65!black,
            enlarge top by=10mm,
            overlay={%
                \path[fill=blue!65,line width=.4mm] (frame.north west)--++(17mm,0)coordinate(n2)--++(0,8mm)--++(-20mm,0) arc (-90:90:-4mm)--cycle;
                \node at ([shift={(5mm,4mm)}]frame.north west){\color{white}{\textbf{\sffamily Exercise}}};
                \path[fill=green!65!blue] ([xshift=.4mm]n2)--++(0,8mm)--++(7mm,0)--++(0,-8mm)--cycle;
                \node at ([shift={(4mm,4mm)}]n2){\color{white}{\textbf{\sffamily \themycounter}}};
                \path[fill=blue!65,line width=.4mm] (frame.north east)--++(6mm,0)coordinate(n3)--++(0,8mm)--++(-20mm,0) arc (-90:90:-4mm)--cycle;
                \node at ([shift={(-8mm,4mm)}]frame.north east){\color{white}{\itshape\textbf{\sffamily MyTitle}}};
    }}}
    
    Before... 
    
    \begin{tcolorbox}[exercisebox,step=mycounter,label=one]
        My exercise here...
    \end{tcolorbox}
    
    After...
    
\end{document}

You must log in to answer this question.

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