我正在使用pgfplotstableset
和longtable
从文件中读取数据并将其格式化为由多个子表组成的表。我已成功创建表格并在其上添加标题。但是,我还想在每个子表上添加子标题,但我无法做到这一点。
我已经使用 创建了上面的表格caption*
。但是,我更愿意使用subcaption
来保持引用的一致性。下面,我包含了创建上面表格时使用的最少代码。我尝试用 替换,caption*
但subcaption
出现以下错误:
! Package caption Error: \subcaption outside float.
最少代码。article.tex:
\documentclass{article}
\usepackage{conf-simple}
\begin{document}
\includetable{data/minimal-data.dat}{Minimal data}{minimal-data}
\end{document}
conf-simple.sty:
\ProvidesPackage{conf-simple}
\usepackage{subcaption}
\usepackage{pgfplotstable}
\usepackage{longtable}
\usepackage{booktabs}
\pgfplotstableset{
begin table=\begin{longtable},
create on use/double/.style={create col/expr={\thisrowno{1}*2}},
end table=\end{longtable},
}
\newcommand{\includetable}[3]{
\noindent\begin{minipage}{\textwidth}
\pgfplotstabletypeset[
col sep=space,
header=false,
column type=r,
columns={0,1,double}, % display specified columns
columns/0/.style={string type, column name =},
columns/1/.style={column name=\small{Value}},
columns/double/.style={column name=\small{Double}},
% requires booktabs to place horiz rules
every head row/.style={before row={\caption{#2 \label{table:#3}} \\ \caption*{(a) First subtable} \\ \toprule
\multicolumn{3}{|c|}{Numbers} \\ \midrule}, after row=\midrule},
every last row/.style={after row=\bottomrule},
every first column/.style={column type/.add={|}{}},
every column/.style={column type/.add={}{|}},
]{#1}
\end{minipage}
\noindent\begin{minipage}{\textwidth}
\pgfplotstabletypeset[col sep=space,
header=false,
columns={0,1}, % display specified columns
columns/0/.style={string type,column name=},
columns/1/.style={column name=\small{Value}},
% requires booktabs to place horiz rules
every head row/.style={before row={\caption*{(b) Second subtable} \\ \toprule
\multicolumn{2}{|c|}{Numbers} \\ \midrule }, after row=\midrule},
every last row/.style={after row=\bottomrule},
every first column/.style={column type/.add={|}{}},
every column/.style={column type/.add={}{|}},
]{#1}
\end{minipage}
}
\end{document}
最小数据文件:
One 1
Two 2
Three 3
据我了解,该问题与longtable
不接受子标题有关,但我不知道如何以不同的方式构建我的表格。
答案1
仅\fixsubtable
在小页面或其他组内使用。
\documentclass{article}
\usepackage{subcaption}
\usepackage{longtable}
\makeatletter
\newcommand{\fixsubtable}{\let\caption=\caption@caption
\def\@captype{table}}
\makeatother
\begin{document}
\begin{longtable}{@{}c@{}}
\caption{No Data}
\endhead
\endfoot
\begin{minipage}{\textwidth}
\fixsubtable
\subcaption{First subtable}
\centering
\rule{0.25\textwidth}{0.25\textwidth}
\end{minipage}\\
\end{longtable}
\end{document}