1

The following compiles under cleveref v0.19 and tcolorbox v3.80 with TeXLive 2013 under osx 10.6.8 but the reference does not work. I have added an example (commented out) from the doc where the reference does work.

% !TEX TS-program = pdflatexmk  
\documentclass{book}

\usepackage{cleveref}
\usepackage{tcolorbox}  

%\newtcolorbox[auto counter,number within= chapter, crefname={bluebox}{blueboxes}] {mybluebox}[2][]{colback=blue!5!white,colframe=blue!75!black,fonttitle=\bfseries,title=Bluebox \thetcbcounter: #2,#1}

\newtcolorbox[auto counter,number within=chapter,crefname={example}{examples},Crefname={EXAM}{EXAMS}]{EXAM}[2][]{fonttitle=\small\sffamily,detach title,before upper={\tcbtitle\quad},fontupper=\small\sffamily,coltitle=black,colback=white, colframe=white,title={\textbf{E\footnotesize{XAM} \small{\thetcbcounter}: #2,#1}}}

\begin{document}
\chapter{One}

%\begin{mybluebox}[label={myreference}]{My title} 
%This is an example
%\end{mybluebox}
%\Cref{myreference} on \cpageref{myreference}

\begin{EXAM}[label={zap}]{Some Title}
This is my own box.
\end{EXAM}
\Cref{zap} on \cpageref{zap}

\end{document}
1
  • 1
    The reference in the documentation example works because of the limiting of , for the title argument. The title ends at #2, after that the optional argument #1 comes into action
    – user31729
    Mar 6, 2016 at 17:49

1 Answer 1

3

There is a typo or wrongly set } in the definition of EXAMS box:

Original version:

title={\textbf{E\footnotesize{XAM} \small{\thetcbcounter}: #2,#1}

This means that the label={zap} is appended to the title, which is pretty useless.

The correct form is of course

\newtcolorbox[auto counter,number within=chapter,crefname={example}{examples},Crefname={EXAM}{EXAMS}]{EXAM}[2][]{%
  fonttitle=\small\sffamily,detach title,
  before upper={\tcbtitle\quad},
  fontupper=\small\sffamily,
  coltitle=black,colback=white, 
  colframe=white,
  title={\textbf{E\footnotesize{XAM} \small{\thetcbcounter}: #2}},
  #1
}

i.e. closing title={...}, then applying the optional argument #1.

\documentclass{book}

\usepackage{cleveref}
\usepackage{tcolorbox}  

%\newtcolorbox[auto counter,number within= chapter, crefname={bluebox}{blueboxes}] {mybluebox}[2][]{colback=blue!5!white,colframe=blue!75!black,fonttitle=\bfseries,title=Bluebox \thetcbcounter: #2,#1}

\newtcolorbox[auto counter,number within=chapter,crefname={example}{examples},Crefname={EXAM}{EXAMS}]{EXAM}[2][]{%
  fonttitle=\small\sffamily,detach title,
  before upper={\tcbtitle\quad},
  fontupper=\small\sffamily,
  coltitle=black,colback=white, 
  colframe=white,
  title={\textbf{E\footnotesize{XAM} \small{\thetcbcounter}: #2}},
  #1
}

\begin{document}
\chapter{One}

%\begin{mybluebox}[label={myreference}]{My title} 
%This is an example
%\end{mybluebox}
%\Cref{myreference} on \cpageref{myreference}

\begin{EXAM}[label={zap}]{Some Title}
This is my own box.
\end{EXAM}
\Cref{zap} on \cpageref{zap}

\end{document}

In conjunction with such settings with tcolorbox it's a good idea to provide the options on a separate line for each option.

enter image description here

3
  • Would you believe I spent several hours looking for an error even though it is my standard procedure to "provide the options on a separate line for each option"? (That's because I am only a user with no time left to really learn and understand LaTeX.)
    – schremmer
    Mar 6, 2016 at 18:23
  • @schremmer: I actually wanted to say that it's better to use one line per option to make the usage more distinguishable. LaTeX actually doesn't care about one line per option or writing them all in one line only ;-)
    – user31729
    Mar 6, 2016 at 20:44
  • @ Christian Hupfer That much I knew. But what I don't really know is the use of % at the end of each line. But that's for another time.
    – schremmer
    Mar 6, 2016 at 23:54

You must log in to answer this question.

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