我使用主题中的代码:如何使表格/表格出现在 tcolorbox 中?
但是错误“不在外部模式”并且表格没有出现。
最小代码:
\documentclass[12pt,a4paper]{article}
\usepackage{mwe}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[x11names,table]{xcolor} % dddd%
\usepackage{eurosym}
\usepackage{datetime}
\settimeformat{ampmtime}
\usepackage{hyperref}
\hypersetup{colorlinks=true, urlcolor=blue}
\usepackage{graphicx,subcaption}
\usepackage{tcolorbox}
\begin{document}
\begin{tcolorbox}[colback=gray!5!white,colframe=gray!75!black,title=\large{In the next lines I'm trying to insert the same in a box}]
\begin{table}[h!]
\centering
\begin{tabular}{|c|c|c|c|}
\hline
% after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
a& b & T/F & dif\\ \hline
1 & 2 & False & -1\\
2 & 4 & False & -2\\
\hline
\end{tabular}\\
\caption{Caption Table}\label{tab:table-out}
\end{table}
\end{tcolorbox}
\end{document}
答案1
您不应table
在框中插入浮动。将其移除,并使用\captionof
(在包中的caption
和中定义的capt-of
)命令作为标题:
\documentclass[12pt,a4paper,
x11names,table]{article}
\usepackage{tcolorbox}
\usepackage[skip=1ex]{caption}
\begin{document}
\begin{tcolorbox}[colback=gray!5!white,colframe=gray!75!black,title=\large{In the next lines I'm trying to insert the same in a box}]
\centering
\begin{tabular}{|c|c|c|c|}
\hline
% after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
a& b & T/F & dif\\ \hline
1 & 2 & False & -1\\
2 & 4 & False & -2\\
\hline
\end{tabular}\\
\captionof{figure}{Caption Table}\label{tab:table-out}
\end{tcolorbox}
\end{document}
答案2
tcolorbox
允许将您的图形和表格转换为漂亮的浮动彩色框。blend into=tables
选项使用tcolorbox
标题作为说明文字,并将表格计数器和说明文字添加到listoftables
。如果您希望 tcolorbox 适应表格大小,capture=hbox
请这样做。
\documentclass[12pt,a4paper]{article}
\usepackage{tcolorbox}
\usepackage{hyperref}
\hypersetup{colorlinks=true, urlcolor=blue}
\newtcolorbox[blend into=tables]{mytable}[2][]{float=htb, title={#2},
every float=\centering, before upper=\centering, #1}
\begin{document}
\listoftables
\begin{mytable}{A nice floating table in tcolorbox format}
\begin{tabular}{|c|c|c|c|}
\hline
% after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
a& b & T/F & dif\\ \hline
1 & 2 & False & -1\\
2 & 4 & False & -2\\
\hline
\end{tabular}
\end{mytable}
\begin{mytable}[capture=hbox, colback=red!10, colframe=red!40!black]{Another nice floating table in tcolorbox format}
\begin{tabular}{|c|c|c|c|}
\hline
% after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
a& b & T/F & dif\\ \hline
1 & 2 & False & -1\\
2 & 4 & False & -2\\
\hline
\end{tabular}
\end{mytable}
\end{document}
答案3
您想要浮动tcolorbox
:
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[x11names,table]{xcolor} % dddd%
\usepackage{eurosym}
\usepackage{datetime}
\usepackage{graphicx,subcaption}
\usepackage{tcolorbox}
\usepackage{hyperref}
\hypersetup{colorlinks=true, urlcolor=blue}
\settimeformat{ampmtime}
\begin{document}
\begin{table}[htp!]
\begin{tcolorbox}[
colback=gray!5!white,
colframe=gray!75!black,
title=\large{In the next lines I'm trying to insert the same in a box}
]
\centering
\begin{tabular}{|c|c|c|c|}
\hline
% after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
a& b & T/F & dif\\ \hline
1 & 2 & False & -1\\
2 & 4 & False & -2\\
\hline
\end{tabular}
\caption{Caption Table}\label{tab:table-out}
\end{tcolorbox}
\end{table}
\end{document}
不,你不想要只是h!
,因为表格不太可能适合“正确的位置”。如果它去了其他地方,不要担心,请参阅如何影响 LaTeX 中图形和表格等浮动环境的位置?