是否可以将table
环境插入到tcolorbox
由包提供的环境中tcolorbox
?
% !TEX program = pdflatex
% arara: pdflatex: {synctex: yes}
\documentclass[a4paper,11pt]{report}
% Generali
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{microtype}
\usepackage[italian]{varioref}
\usepackage{relsize}
\usepackage{lipsum}
\usepackage{tabularx}
% Riquadri
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\begin{document}
\begin{tcolorbox}[adjusted title= Box1: Title.]
%\begin{table}[tb]
\begin{tabular}{cc}
a & b \\
c & d
\end{tabular}
%\end{table}
\end{tcolorbox}
\end{document}
有没有办法插入table
带有caption
和的label
?
答案1
tcolorbox
(顾名思义)是一个盒子;table
是一个浮点数,而在盒子里面,浮点数被卡住了......这就是它不起作用的原因。
只需使用表格,并使用\captionof
fromcapt-of.sty
或(iirc)caption.sty
(它有很多选项,我不太确定)为其添加标题。
答案2
tcolorbox
-es 也可以float
,您可以声明为和tcolorboxes
来引用。以下代码声明了一个浮动框。标题前面会有和选项,可用于引用。figures
tables
mytable
Table #
label
\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lmodern}
\usepackage{lipsum}
\newtcolorbox[blend into=tables]{mytable}[2][]{float=htb, halign=center, title={#2}, every float=\centering, #1}
\begin{document}
\lipsum[1]
\begin{mytable}[float=t, label=myref]{This is a floating box}
\begin{tabular}{cc}
a & b \\
c & d
\end{tabular}
\end{mytable}
{\Large As you can see in table~\ref{myref} \dots}
\lipsum[2]
\end{document}
答案3
您不能将表格放在框内。但您可以反过来做——将框放在表格内:
% !TEX program = pdflatex
% arara: pdflatex: {synctex: yes}
\documentclass[a4paper,11pt]{report}
% Generali
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{microtype}
\usepackage[italian]{varioref}
\usepackage{relsize}
\usepackage{lipsum}
\usepackage{tabularx}
% Riquadri
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\begin{document}
\begin{table}[tb]
\caption{This is table}
\label{tab:mytable}
\begin{tcolorbox}[adjusted title= Box1: Title.]
%\begin{table}[tb]
\begin{tabular}{cc}
a & b \\
c & d
\end{tabular}
%\end{table}
\end{tcolorbox}
\end{table}
As per Table~\ref{tab:mytable}, this works.
\end{document}