1

On page 99 of the tcolorbox 3.80 manual, there is an example, given a new tcolorbox, of how to retrieve the name of the tcolorbox, i.e "BlueBox", (\nameCref{myreference}), the counter number of the particular tcolorbox, i.e, "0.0.1" (\labelcref{myreference}), and the page number, i.e. "99" in the manual (\labelcpageref{myreference}).

What I cannot figure out is how to retrieve the title of the particular tcolorbox, i.e. "My title".

Here is the code:

\documentclass[11pt]{book}
\usepackage{tcolorbox}
\usepackage{cleveref}
\newtcolorbox[%
auto counter,%
number within=section,%
crefname={bluebox}{blueboxes}%
]% 
{%
mybluebox%
}%
[2][]%
{%
colback=blue!5!white,%
colframe=blue!75!black,%
fonttitle=\bfseries,%
title=Bluebox \thetcbcounter: #2,#1%
}%

\begin{document}

\begin{mybluebox}[label={myreference}]{My title}
This is an example.
\end{mybluebox}

\nameCref{myreference}

\labelcref{myreference}

\labelcpageref{myreference}

\end{document}
4

You can add a nameref attribute to the tcolorbox definition. This attribute can be accessed using the label name with the \nameref command (which requires loading the nameref package).

MWE:

\documentclass[11pt]{book}
\usepackage{tcolorbox}
\usepackage{cleveref}
\usepackage{nameref}
\newtcolorbox[auto counter,number within=section,crefname={bluebox}{blueboxes}]{mybluebox}[2][]%
{colback=blue!5!white,colframe=blue!75!black,fonttitle=\bfseries,%
title=Bluebox \thetcbcounter: #2,%
nameref=#2,%
#1}

\begin{document}

\begin{mybluebox}[label={myreference}]{My title}
This is an example.
\end{mybluebox}

\nameCref{myreference}

\labelcref{myreference}

\labelcpageref{myreference}

Title: \nameref{myreference}.

\end{document}

Result:

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.