0

Similar to this, but how do I make it using \newtcbtheorem? I want to avoid duplicates on names since it gives warnings.

For example, the definition on the first section will have a name tcb@[email protected], I think. Then, as I declare another section and make another definition, it will have the same name, thus the duplicate.

2 Answers 2

1

enter image description here It's pretty simple:

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\newtcbtheorem[number within=section]{dfn}{Definition}{}{}

\begin{document}
\section{First Section}
\begin{dfn}{}{}
    Here is a definition
\end{dfn}
\begin{dfn}{}{}
    Here is a second definition
\end{dfn}
\section{A New Section}
\begin{dfn}{}{}
    Here is a third definition
\end{dfn}
\end{document}

The number within key sets the number to reset each time you call \section. Or to have the numbering change with every subsection use number within=subsection.

5
  • That is what I used, though it seems that the count for the second section is a duplicate of the first section.
    – soupless
    Apr 1, 2021 at 16:35
  • I don't know how should I make the MWE since I made one, but it worked. The warning is like this: pdfTeX warning (ext4): destination with the same identifier (name{tcb@cnt@df n.1}) has been already used, duplicate ignored <to be read again> \relax l.148 ...begin{dfn}{Integration by Substitution}{}, by the way.
    – soupless
    Apr 2, 2021 at 9:05
  • Since you are getting an error your MWE should be code that someone can copy and paste and recreate the same error. This means you need a \documentclass, both \begin{document} and \end{document}, all relevant packages (but not irrelevant packages) and the minimal code required in the document to cause the error to occur.
    – Willoughby
    Apr 2, 2021 at 9:21
  • I know how to make an MWE but the problem is that I don't know where the problem occurred. Your example is exactly what I did in the first place and yet, the compiler treats the tcolorboxes as duplicates.
    – soupless
    Apr 2, 2021 at 13:03
  • I recommend copying and pasting your work into a new document. If the issue persists delete parts of the code and recompile until either the error disappears or the output no longer shows what you want, add that section back in. Use what you are left with as an MWE.
    – Willoughby
    Apr 2, 2021 at 13:44
0

This errors probably comes from the use of hyperref package. It automatically creates links between labelled elements and references to them, but all labels must be different.

Every dfn created from tcolorbox definition, automatically creates a label with the prefix fixed in last parameter in \newtcbtheorem definition and the second mandatory parameter in each \begin{dfn}{}{}. If prefix and suffix are empty every definition will have a similar label and hyperref will show the error message.

I suggest to use something like this to avoid the error message:

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\newtcbtheorem[number within=section]{dfn}{Definition}{}{dfn}
\usepackage{hyperref}

\begin{document}
\section{First Section}
\begin{dfn}{}{a}
    Here is a definition
\end{dfn}
\begin{dfn}{}{b}
    Here is a second definition
\end{dfn}
\section{A New Section}
\begin{dfn}{}{c}
    Here is a third definition
\end{dfn}

This is the first definition: \ref{dfn:a}, this is the second, \ref{dfn:b} and this the last one, \ref{dfn:c}.
\end{document}

enter image description here

1
  • I remember doing this, but I guess I'll try to do it again. Maybe it will work now.
    – soupless
    Apr 5, 2021 at 9:05

You must log in to answer this question.

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