
原因如下浮點數不能嵌套在 tcolorbox 中我希望我的(子)人物更漂亮,我寫了新的Figure
和Subfigure
newtcolorbox 環境。這是我的程式碼的簡化版本
\documentclass[12pt,a4paper]{book}
\usepackage{lipsum}
\usepackage[skins, breakable]{tcolorbox}
\newcommand{\figref}[1]{Figure \ref{fig:#1}}
\newtcolorbox[auto counter]{Figure}[1]{
title = {Figure~\thetcbcounter~$-$ #1}
}
\newtcolorbox[
auto counter,
number within=tcb@cnt@Figure,
number freestyle = {(\noexpand\alph{\tcbcounter})}
]
{Subfigure}[3][]{
width = (\linewidth - 4\dimexpr (#2pt - 1pt)\relax)/#2,
before =,
after = \hfill,
box align = center,
title = {\thetcbcounter~#3},
#1
}
\begin{document}
\begin{Figure}
{Title figure}
\begin{Subfigure}[label={fig:a}]{2}
{Title again}
\lipsum[1]
\end{Subfigure}%
%
\begin{Subfigure}{2}
{A nice Subfigure}
\lipsum[2]
\end{Subfigure}
\end{Figure}
See \figref{a}.
\end{document}
與輸出
我喜歡這個結果,但我希望打印文本Figure 1a
,而Figure (a)
不是更改子圖的標題。更準確地說,我可以number freestyle
將 newtcolorbox 的參數更改1a
為我的子圖的計數器,但這會將標題更改為(a) blabla
我1a blabla
不想要的標題。
hyperref
請注意,即使我從最小工作範例中刪除了包,我仍然使用它。
我認識一個類似的問題已被問到,但我不知道它與我的問題有多接近,因為我不明白什麼
\makeatletter
\newcommand{\customlabel}[2]{%
\protected@write \@auxout {}{\string \newlabel {#1}{{#2}{}}}}
\makeatother
是在做...
答案1
您可以使用變更標籤格式\labelformat
(請參閱ltnews30.pdf
了解更多):
\documentclass[12pt,a4paper]{book}
\usepackage{lipsum}
\usepackage[skins, breakable]{tcolorbox}
\newcommand{\figref}[1]{Figure \ref{fig:#1}}
\newtcolorbox[auto counter]{Figure}[1]{
title = {Figure~\thetcbcounter~$-$ #1}
}
\newtcolorbox[
auto counter,
number within=tcb@cnt@Figure,
number freestyle = {(\noexpand\alph{\tcbcounter})}
]
{Subfigure}[3][]{
width = (\linewidth - 4\dimexpr (#2pt - 1pt)\relax)/#2,
before =,
after = \hfill,
box align = center,
title = {\thetcbcounter~#3},
#1
}
\labelformat{tcb@cnt@Subfigure}{\arabic{tcb@cnt@Figure}\alph{tcb@cnt@Subfigure}}
\begin{document}
\begin{Figure}
{Title figure}
\begin{Subfigure}[label={fig:a}]{2}
{Title again}
\lipsum[1]
\end{Subfigure}%
%
\begin{Subfigure}{2}
{A nice Subfigure}
\lipsum[2]
\end{Subfigure}
\end{Figure}
See \figref{a}.
\end{document}
順便說一句:我建議也使用cleveref
而不是定義您自己的\figref
.