エラー: 外部 par モードではありません: tcolorbox 内のテーブル

エラー: 外部 par モードではありません: tcolorbox 内のテーブル

トピックのコードを使用します: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 で図や表などのフロート環境の位置に影響を与えるにはどうすればよいでしょうか?

関連情報