Error: no en modo par externo: tabla dentro de tcolorbox

Error: no en modo par externo: tabla dentro de tcolorbox

uso el código del tema:¿Cómo hacer que una tabla/tabular aparezca en un tcolorbox?

Pero el error "No en modo par externo" y la tabla no aparece.

Código mínimo:

\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}

ingrese la descripción de la imagen aquí ¿Cómo puedo arreglarlo? Gracias

Respuesta1

ingrese la descripción de la imagen aquí

No debes insertar un flotador tableen la caja. Elimínelo y para el uso de subtítulos \captionof(definido en el comando captiony en capt-ofel paquete):

\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}

Respuesta2

tcolorboxpermite convertir tus figuras y tablas en bonitas cajas flotantes de colores. blend into=tablesLa opción utiliza el tcolorboxtítulo como título y agrega el contador de la tabla y el título en listoftables. Si prefieres que tcolorbox se ajuste al tamaño de la tabla, capture=hboxhazlo.

\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}

ingrese la descripción de la imagen aquí

Respuesta3

Quieres hacer flotar el 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}

ingrese la descripción de la imagen aquí

Y no, no querrás simplemente h!, porque es muy poco probable que una mesa quepa en el “lugar correcto”. No te preocupes si va a otro lado, mira¿Cómo influir en la posición de entornos flotantes como figuras y tablas en LaTeX?

información relacionada