我想在 tbox 内使用表格(带有标题和标签),但出现在 tbox 外部的相同表格却没有出现在内部。
我该怎么办?有什么问题?
代码如下:
\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}
\usepackage[spanish]{cleveref} %para crear referencias
% poner las dos siguientes líneas despues de begin- document % Type the next two lines after begin-document
\renewcommand{\tablename}{Tabla}
\crefname{table}{tabla}{tablas}
\begin{document}
\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}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\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, using \emph{tcolorbox} package.}]
\tcblower
\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}
\textbf{Question}
\begin{itemize}
\item What's ...?
\end{itemize}
\end{tcolorbox}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
答案1
您可以使用带有环境选项的Float
包H
table
\documentclass[12pt,a4paper]{article}
\usepackage{mwe}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[x11names,table]{xcolor} % dddd%
\usepackage{eurosym}
\usepackage{float}
\usepackage{datetime}
\settimeformat{ampmtime}
\usepackage{hyperref}
\hypersetup{colorlinks=true, urlcolor=blue}
\usepackage{graphicx,subcaption}
\usepackage{tcolorbox}
\usepackage[spanish]{cleveref} %para crear referencias
% poner las dos siguientes líneas despues de begin- document % Type the next two lines after begin-document
\renewcommand{\tablename}{Tabla}
\crefname{table}{tabla}{tablas}
\begin{document}
\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}
\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, using \emph{tcolorbox} package.}]
\tcblower
\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}
\textbf{Question}
\begin{itemize}
\item What's ...?
\end{itemize}
\end{tcolorbox}
\end{document}
答案2
table
是浮点数,您不能将浮点数放在minipage
或里面box
(例如tcolorbox
)。但相反的做法是可以的 → 将 放在tcolorbox
里面table
。
\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}
\usepackage[spanish]{cleveref} %para crear referencias
% poner las dos siguientes líneas despues de begin- document % Type the next two lines after begin-document
\renewcommand{\tablename}{Tabla}
\crefname{table}{tabla}{tablas}
\begin{document}
\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}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{table}[h!]
\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, using \emph{tcolorbox} package.}]
\tcblower %% why this line?
\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}
\textbf{Question}
\begin{itemize}
\item What's ...?
\end{itemize}
\end{tcolorbox}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}