1

I have a document in which I define new environment for examples (MWE below). In it, I define the prefix for referencing it, which is simple example:nameofexample.

Now, when working with \autoref I can simply write \autoref{eq:name} and the result is written along the lines of Equation 1.37 (i.e. the word "Equation" is prefixed to the referenced equation number). I do this by defining

\usepackage{hyperref}
\def\equationautorefname{Equation}

I would like to do something similar with autorefs to an example, e.g. \def\exampleautorefname{Example}

How do I do that?

The MWE code:

\documentclass{article}
\usepackage{xcolor}
\definecolor{xblue}{HTML}{4268BD}
\usepackage[most]{tcolorbox}
\tcbset{
    common/.style n args={2}{
        colframe={#1},
        colback={#1!5},
        colbacktitle={#1},
        lower separated=false,
        coltitle=white,
        boxrule=1pt,
        fonttitle=\bfseries,
        enhanced,
        breakable,
        top=8pt,
        before skip=1em,
        after skip=2em,
        attach boxed title to top left={
            yshift=-0.25cm,
            xshift=0.38cm,
        },
        boxed title style={
            boxrule=0pt,
            colframe=white,
            arc=5pt,
            outer arc=4pt,
        },
        separator sign={~~},
        overlay unbroken and last={
            \node[text=white, align=right, rounded corners, fill=#1, xshift=-4mm, minimum height=6mm, anchor=east] at (frame.south east) {#2};
        }
    },
    examplestyle/.style={
        common={xblue}{!},
    },
}
\newtcbtheorem{example}{Example}{examplestyle}{example}

\usepackage{hyperref}
\def\equationautorefname{Equation}
\def\exampleautorefname{Example}

\usepackage{blindtext}

\begin{document}
This is an example box:
\begin{example}{This is an example}{myexample}
    \blindtext[1]
\end{example}

And here is an equation:
\begin{equation}
    a+b=c
    \label{eq:myeq}
\end{equation}

\vspace{1em}
Now I try to autorefence both the equation and the example: \autoref{example:myexample} and \autoref{eq:myeq}. While in the case of the autoref to the equation, it shows ``Eqaution 1``. For the example autoref though, it only shows ``1``. How can I add new categories to autoref so that it instead shows ``Example 1``?
\end{document}

The result of compiling the above code: enter image description here

1 Answer 1

2

If you take a look into the log you will see that hyperref tells you what is missing

Package hyperref Warning: No autoref name for `tcb@cnt@example' on input line 9

tcb@cnt@example is the internal counter name used by tcolorbox. So add

\makeatletter
\def\tcb@cnt@exampleautorefname{Example}
\makeatother
1
  • Amazing, thank you :) (und frohe Ostern!)
    – pelegs
    Apr 16 at 19:03

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.