通过 tcolorbox 编号(编号为“section.box”)对表格(图像等)进行编号

通过 tcolorbox 编号(编号为“section.box”)对表格(图像等)进行编号

我正在使用 tcolorboxes 作为存储表格、图像等的环境。这些框本身是用section.box内置tcolorbox编号来编号的,我想用\captionof每个框中的框数来标记多个表格/图像(用 } 计数),所以我会Table 1.3aBox 1.3Figure 2.4b中看到类似的东西Box 2.4。现在我已经阅读了\newcounter\refstepcounter\renewcommand(对于tabletabular),但我似乎无法理解如何实现这一目标。请提供意见。

\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)。

我的做法是:让tcolorboxes 使用一个已知的计数器,并定义一个使用第一个计数器重置的新计数器。然后我手动定义了类似 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}}重置计数器。这可以通过 来完成。tabletcolorboxabefore 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}

在此处输入图片描述

相关内容