2

I want to use tables ( with caption and label) inside tbox, but The SAME table that appears outside the tbox, doesn´t appear inside.

How could I do?, What´s the problem?

The code is:

\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} 
Mika Ike
  • 3,751
  • 1
    I think you can't use floats inside tcolorbox. If you remove the table environment it will work. – jak123 Oct 22 '15 at 07:35
  • You can use \captionof{table}{Caption Table}\label{tab:table-out} to get captions outside the table environment (but check the numbering if you mix floats and non-floats) – Ulrike Fischer Oct 22 '15 at 07:55

2 Answers2

3

table is a float and you cant put a float inside a minipage or box (like tcolorbox). But the reverse is possible → put the tcolorbox inside the 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} 

enter image description here

2

You can use Float package with H option for table environment

\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} 
Salim Bou
  • 17,021
  • 2
  • 31
  • 76