我正在使用 tcolorboxes 作为存储表格、图像等的环境。这些框本身是用section.box
内置tcolorbox
编号来编号的,我想用\captionof
每个框中的框数来标记多个表格/图像(用 } 计数),所以我会Table 1.3a
在Box 1.3
或Figure 2.4b
中看到类似的东西Box 2.4
。现在我已经阅读了\newcounter
、\refstepcounter
和\renewcommand
(对于table
或tabular
),但我似乎无法理解如何实现这一目标。请提供意见。
\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{capt-of}
\usepackage{tcolorbox}
\newtcolorbox[auto counter,number within=section]{cusbox}[2][]{%
before skip=6pt, after skip=6pt,%
halign upper=center,halign lower=center,%
colbacktitle=green!15!white,coltitle=black,colback=green!5!white,colframe=green!75!black,%
leftrule=2mm,rightrule=2mm,titlerule=1mm,%
toptitle=1mm,bottomtitle=1mm,center title,title=Box \thetcbcounter: #2,#1}
\usepackage{lipsum}
\begin{document}
\section{Tcolorbox}
\lipsum[1]
\begin{cusbox}[sidebyside,label=box:table]{The Tables Have Turned}
\begin{tabular}{ccc}
\textbf{one} & \textbf{two} & \textbf{three} \\
\hline
5646 & 5651 & 65654 \\
56645 & 465 & ksldk
\end{tabular}
\captionof{table}{Actual data (not really)}\label{table:table1}
\tcblower
\begin{tabular}{ccc}
\textbf{one} & \textbf{two} & \textbf{three} \\
\hline
5646 & 5651 & 65654 \\
56645 & 465 & ksldk
\end{tabular}
\captionof{table}{Actual data (not really)}\label{table:table2}
\end{cusbox}
\lipsum[2]
\end{document}
答案1
这是另一种选择 --- 更加手动,并且没有表格所具有的花哨的东西(也许您可以尝试找到一种方法将其与之集成newfloat
)。
我的做法是:让tcolorbox
es 使用一个已知的计数器,并定义一个使用第一个计数器重置的新计数器。然后我手动定义了类似 caption 的命令。
\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{capt-of}
\usepackage{tcolorbox}
\newcounter{boxes}
\newtcolorbox[use counter=boxes,number within=section]{cusbox}[2][]{%
before skip=6pt, after skip=6pt,%
halign upper=center,halign lower=center,%
colbacktitle=green!15!white,coltitle=black,colback=green!5!white,colframe=green!75!black,%
leftrule=2mm,rightrule=2mm,titlerule=1mm,%
toptitle=1mm,bottomtitle=1mm,center title,title=Box \thetcbcounter: #2,#1%
}
\newcounter{intable}[boxes]
\renewcommand{\theintable}{\theboxes\alph{intable}}
\newcommand{\myintable}[1]{%
\refstepcounter{intable}\par\textbf{Table \theintable} #1%
}
\usepackage{lipsum}
\begin{document}
\section{Tcolorbox}
\lipsum[1]
\begin{cusbox}[sidebyside,label=box:table]{The Tables Have Turned}
\begin{tabular}{ccc}
\textbf{one} & \textbf{two} & \textbf{three} \\
\hline
5646 & 5651 & 65654 \\
56645 & 465 & ksldk
\end{tabular}
\myintable{Actual data (not really)}\label{intable:table1}
\tcblower
\begin{tabular}{ccc}
\textbf{one} & \textbf{two} & \textbf{three} \\
\hline
5646 & 5651 & 65654 \\
56645 & 465 & ksldk
\end{tabular}
\myintable{Actual data (not really)}\label{intable:table2}
\end{cusbox}
\bigskip
\textbf{References:} \ref{intable:table1} and \ref{intable:table2}
\bigskip
\lipsum[1]
\begin{cusbox}[sidebyside,label=box:table2]{The Tables Have Turned}
\begin{tabular}{ccc}
\textbf{one} & \textbf{two} & \textbf{three} \\
\hline
5646 & 5651 & 65654 \\
56645 & 465 & ksldk
\end{tabular}
\myintable{Actual data (not really)}\label{intable:table3}
\tcblower
\begin{tabular}{ccc}
\textbf{one} & \textbf{two} & \textbf{three} \\
\hline
5646 & 5651 & 65654 \\
56645 & 465 & ksldk
\end{tabular}
\myintable{Actual data (not really)}\label{intable:table4}
\end{cusbox}
\textbf{New References:} \ref{intable:table3} and \ref{intable:table4}
\textbf{Old References:} \ref{intable:table1} and \ref{intable:table2}
\end{document}
答案2
类似 的操作将改变表格的格式,但您需要在每个新框之后\renewcommand{\thetable}{\thetcbcounter\alph{table}}
重置计数器。这可以通过 来完成。table
tcolorbox
a
before upper={\setcounter{table}{0}}
\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{capt-of}
\usepackage{tcolorbox}
\newtcolorbox[auto counter,number within=section]{cusbox}[2][]{%
before upper={\setcounter{table}{0}},
before skip=6pt, after skip=6pt,%
halign upper=center,halign lower=center,%
colbacktitle=green!15!white,coltitle=black,colback=green!5!white,colframe=green!75!black,%
leftrule=2mm,rightrule=2mm,titlerule=1mm,%
toptitle=1mm,bottomtitle=1mm,center title,title=Box \thetcbcounter: #2,#1}
\usepackage{lipsum}
\renewcommand{\thetable}{\thetcbcounter\alph{table}}
\begin{document}
\section{Tcolorbox}
\lipsum[1]
\begin{cusbox}[sidebyside,label=box:table]{The Tables Have Turned}
\begin{tabular}{ccc}
\textbf{one} & \textbf{two} & \textbf{three} \\
\hline
5646 & 5651 & 65654 \\
56645 & 465 & ksldk
\end{tabular}
\captionof{table}{Actual data (not really)}\label{table:table1}
\tcblower
\begin{tabular}{ccc}
\textbf{one} & \textbf{two} & \textbf{three} \\
\hline
5646 & 5651 & 65654 \\
56645 & 465 & ksldk
\end{tabular}
\captionof{table}{Actual data (not really)}\label{table:table2}
\end{cusbox}
\lipsum[2]
\begin{cusbox}[sidebyside,label=box:table]{The Tables Have Turned}
\begin{tabular}{ccc}
\textbf{one} & \textbf{two} & \textbf{three} \\
\hline
5646 & 5651 & 65654 \\
56645 & 465 & ksldk
\end{tabular}
\captionof{table}{Actual data (not really)}\label{table:table1}
\tcblower
\begin{tabular}{ccc}
\textbf{one} & \textbf{two} & \textbf{three} \\
\hline
5646 & 5651 & 65654 \\
56645 & 465 & ksldk
\end{tabular}
\captionof{table}{Actual data (not really)}\label{table:table2}
\end{cusbox}
\end{document}