I am making a table with two subtables, each subtable has its own tablenotes so I am using threeparttable. But I am prompted with the following error:
! Package caption Error: table inside subtable.
See the caption package documentation for explanation.
Type H for immediate help.
...
l.7 \begin{threeparttable}
If you do not understand this error, please take a closer look
at the documentation of the `caption' package, especially the
section about errors.
A small example of my code here. It gives the error above. I searched around and it seems threeparttable
should be able to work with subcaption
, at least in my simple example here. Could any of you guys ever had issues alike and can point me a way? thanks.
\documentclass{article}
\usepackage{threeparttable}
\usepackage{subcaption}
\begin{document}
\begin{table}
\begin{subtable}{\textwidth}
\begin{threeparttable}
\begin{tabular}{ccc}
test1 &test1 &test1
\end{tabular}
\end{threeparttable}
\end{subtable}
\end{table}
\end{document}
Update 1
Thanks to @cfr's answer, if we put threeparttable
outside subtable
, the compile error would be gone. But we have new problems here. Let's first make clear what we want:
- we want one
table
, which means it has one main caption (Tab 1
). - Inside this top level
table
, we want two subtables, either these subtables are realized by the tagsubtable
or not doesn't matter. - For each subtable, it has its own caption (
Tab a
andTab b
) and table notes.
So now we have the following problem:
- If we put captions for subtable between
threeparttable
andsubtable
(code example as below), the caption for subtable will be using the top level caption counter, we end up withTab 1
,Tab 2
andTab 3
.
\documentclass{article}
\usepackage{threeparttable}
\usepackage{subcaption}
\begin{document}
\begin{table}
\centering
\caption{top level caption}
\begin{threeparttable}
\centering
\caption{sub level caption 1}
\begin{subtable}{\textwidth}
\begin{tabular}{|c|c|c|}
\hline
test1 &test1 &test1\\
\hline
\end{tabular}
\end{subtable}
\end{threeparttable}
\begin{threeparttable}
\centering
\caption{sub level caption 2}
\begin{subtable}{\textwidth}
\begin{tabular}{|c|c|c|}
\hline
test2 &test2 &test2\\
\hline
\end{tabular}
\end{subtable}
\end{threeparttable}
\end{table}
\end{document}
- if we put
caption
inside thesubtable
environment, the are separated by thethreeparttable
and will give us twoTab a
. Code example and pic below.
\documentclass{article}
\usepackage{threeparttable}
\usepackage{subcaption}
\begin{document}
\begin{table}
\centering
\caption{top level caption}
\begin{threeparttable}
\centering
\begin{subtable}{\textwidth}
\caption{sub level caption 1}
\begin{tabular}{|c|c|c|}
\hline
test1 &test1 &test1\\
\hline
\end{tabular}
\end{subtable}
\end{threeparttable}
\begin{threeparttable}
\centering
\begin{subtable}{\textwidth}
\caption{sub level caption 2}
\begin{tabular}{|c|c|c|}
\hline
test2 &test2 &test2\\
\hline
\end{tabular}
\end{subtable}
\end{threeparttable}
\end{table}
\end{document}