3

I'm currently writing a thesis and would like to format my definitions nicely. This question helped me creating a nice layout for my definitions. The following code

\documentclass{book}

\usepackage[most]{tcolorbox}

\newtcolorbox[auto counter,list inside=defs,number within=section]{definition}[2][]{title={Definition~\thetcbcounter},colback={white!30!yellow},colbacktitle={gray},coltitle=black,#1}

\newcommand{\listofdefinitions}{%
 \tcblistof[\section*]{defs}{List of Definitions}
}
\begin{document}
\listofdefinitions

\chapter{Foo}

\section{Foobar}

\begin{definition}[label=latex]{On \LaTeXe}
 \LaTeXe is very nice!
\end{definition}

\begin{definition}[label=MWE]{On MWE}
Providing a MWE helps
\end{definition}

\end{document}

produces this output: enter image description here

What I would like to have, however, is a way to create my own custom definition titles for each definition. I.e. instead of "Definition 1.1.1" and "Definition 1.1.2", I would like to have ""Definition 1.1.1 - My first definition dealing with topic A" and ""Definition 1.1.2 - My second definition dealing with topic B".

Thank you very much for your help.

3
\documentclass{book}

\usepackage[most]{tcolorbox}

\newtcolorbox[auto counter,
list inside=defs,
number within=section]{definition}[2][]{
    list entry={{\bfseries\thetcbcounter~#2}},
    title={Definition~\thetcbcounter\ -- #2},% <-------------
    colback={white!30!yellow},
    colbacktitle={gray},
    coltitle=black,
    #1
}

\newcommand{\listofdefinitions}{%
    \tcblistof[\section*]{defs}{List of Definitions}
}
\begin{document}
    \listofdefinitions

    \chapter{Foo}

    \section{Foobar}

    \begin{definition}[label=latex]{\LaTeXe}
        \LaTeXe is very nice!
    \end{definition}

    \begin{definition}[label=MWE]{MWE}
        Providing a MWE helps
    \end{definition}


\end{document}

Just add the second argument to the title. (I copied Christian's second code in the linked question as it fixes the "list of definitions".) I marked out the relevant change in the code.

enter image description here

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.