以下内容在 osx 10.6.8 下使用 TeXLive 2013 进行编译,cleveref
v0.19
但tcolorbox
v3.80
引用不起作用。我从文档中添加了一个示例(注释掉),其中引用确实起作用。
% !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
}
box的定义有拼写错误或者设置错误EXAMS
:
原始版本:
title={\textbf{E\footnotesize{XAM} \small{\thetcbcounter}: #2,#1}
这意味着将其label={zap}
附加到标题中,这是没用的。
正确的形式当然是
\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
}
即关闭title={...}
,然后应用可选参数#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}
结合此类设置,tcolorbox
最好为每个选项在单独的行上提供选项。