5

For instance, with

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

From (tcolorbox Manual, page 99)

I would like to get Bluebox 5.1 My title instead of just Bluebox 5.1 which is what \Cref{myreference} gives.

1 Answer 1

7

One solution would be to add the title as part of the number using the number freestyle option:

\documentclass{article}

\usepackage{varioref}
\usepackage{cleveref}
\usepackage{tcolorbox}

\newtcolorbox[
  auto counter,
  number within=section,
  number freestyle={\noexpand\thesection.\noexpand\arabic{\tcbcounter}~\noexpand\mytitle},
  crefname={bluebox}{blueboxes}]%
{mybluebox}[2][]{
  colback=blue!5!white,
  colframe=blue!75!black,
  fonttitle=\bfseries,
  code={\def\mytitle{#2}},
  title=Bluebox \thetcbcounter,%
  #1}

\begin{document}

\section{Test}

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

\Cref{myreference}

\end{document}

enter image description here

4
  • It is only now that I tried it and, of course, it works. The only thing is that I do not know how to control the color of My Title in the reference and, since I am using hyperref, My Title appears with the linkcolor. How could I have My Title the same color as Bluebox namely black?
    – schremmer
    Jun 4, 2016 at 3:20
  • @schremmer I do not think that is possible since the whole \Cref{myreference} gets colored with linkcolor... Jun 6, 2016 at 5:51
  • I thought you might perform a miracle but, by now, I got used to it and I even think that's the way it ought to be. So it's just as well. Thanks for a GREAT package. Made my life miserable for a while because now I had to redo properly all the stuff I had done ad hoc. But it was very much worth it.
    – schremmer
    Jun 6, 2016 at 20:36
  • @schremmer You may be interested in question tex.stackexchange.com/questions/315809/… and its answers. Jun 22, 2016 at 8:14

You must log in to answer this question.

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