虽然\cref{vip:1-4}
---wherevip
指的是tcolorbox
---will typoset asAlert 1-4 ∞ is not a number
和\labelcref
will typoset as 1-4 ∞ is not a number
,但有时我想更进一步,只排版∞ is not a number
。
以下是 MWE:
\documentclass[11pt]{book}
\usepackage[hyperfootnotes=false]{hyperref}%
\usepackage{cleveref}%
\usepackage{tcolorbox}%
\newcounter{vip}%
\newtcolorbox%
[%
use counter= vip,
number within=chapter,
number freestyle={\noexpand\thechapter.\noexpand\arabic{\tcbcounter}~\noexpand\mytitlealert},%.
crefname={Alert}{Alert},
Crefname={Alert}{Alerts},
]%
{mportant}%
[2][]%
{%
detach title,%
before upper={\tcbtitle\quad},
fonttitle=\bfseries,
coltitle=black,
code={\gdef\mytitlealert{#2}},%
title=ALERT \thetcbcounter,%
#1,
}%
\begin{document}
\chapter{One}
\begin{mportant}[label={vip:1-4}]{$\infty$ is not a number}
\hspace{-3mm}and we cannot compute with $\infty$.
\end{mportant}
\chapter{Two}
We cannot input $\infty$ because \labelcref{vip:1-4} (\Cpageref{vip:1-4})
\end{document}
并且,偶尔我不希望1.1
在参考文献的开头显示参考编号:
答案1
我建议使用nameref=
选项tcolorbox
(于 2016/6/22 推出(但 CHANGES 文件显示为 2016/7/14),版本 3.94)和而\nameref
不是\labelcref
或\cref
,因为cleveref
这个特殊标题不需要该功能。
我使用是nameref={#2}
因为基本上只应显示标题而不显示其他内容。
\documentclass[11pt]{book}
\usepackage[hyperfootnotes=false]{hyperref}%
\usepackage{tcolorbox}%
\newcounter{vip}%
\usepackage{cleveref}%
\newtcolorbox%
[%
use counter= vip,
number within=chapter,
number freestyle={\noexpand\thechapter.\noexpand\arabic{\tcbcounter}~\noexpand\mytitlealert},%.
crefname={Alert}{Alert},
Crefname={Alert}{Alerts},
]%
{mportant}%
[2][]%
{%
detach title,%
before upper={\tcbtitle\quad},
fonttitle=\bfseries,
coltitle=black,
nameref={#2},
code={\gdef\mytitlealert{#2}},
title={ALERT \thetcbcounter},%
#1,
}%
\begin{document}
\chapter{One}
\begin{mportant}[label={vip:1-4}]{$\infty$ is not a number}
\hspace{-3mm}and we cannot compute with $\infty$.
\end{mportant}
\chapter{Two}
We cannot input $\infty$ because \nameref{vip:1-4} (\Cpageref{vip:1-4})
\end{document}
万一tcolorbox
版本明显过时,可以应用以下by-pass
解决方案,即在选项中定义\@currentlabelname
(由使用\nameref
)code={}
——当然,\makeatletter...\makeatother
除非框的定义写在.sty
或.cls
文件中,否则这是必要的。
\documentclass[11pt]{book}
\usepackage[hyperfootnotes=false]{hyperref}%
\usepackage{tcolorbox}%
\newcounter{vip}%
\usepackage{cleveref}%
\makeatletter
\newtcolorbox%
[%
use counter= vip,
number within=chapter,
number freestyle={\noexpand\thechapter.\noexpand\arabic{\tcbcounter}~\noexpand\mytitlealert},%.
crefname={Alert}{Alert},
Crefname={Alert}{Alerts},
]%
{mportant}%
[2][]%
{%
detach title,%
before upper={\tcbtitle\quad},
fonttitle=\bfseries,
coltitle=black,
code={\gdef\mytitlealert{#2}\edef\@currentlabelname{#2}},%
title={ALERT \thetcbcounter},%
#1,
}%
\makeatother
\begin{document}
\chapter{One}
\begin{mportant}[label={vip:1-4}]{$\infty$ is not a number}
\hspace{-3mm}and we cannot compute with $\infty$.
\end{mportant}
\chapter{Two}
We cannot input $\infty$ because \nameref{vip:1-4} (\Cpageref{vip:1-4})
\end{document}