我想打印一个带有 和 的长表格pgfplotstable
。long tabu
出于某种原因,使用以下代码,我无法在每一页上重复显示标题。我还希望\bottomrule
在每一页上都显示 和 标题,如“表格 xy(续)”。
此外,我指定的宽度也\begin{tabu} to 0.6\linewidth
被忽略。
\documentclass{scrreprt}
\usepackage{array}
\usepackage{tabu}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{siunitx}
\usepackage{caption}
\begin{document}
\pgfplotstableset{
create on use/new/.style = {create col/expr={\pgfplotstablerow+1}}} % Indices of rows
\pgfplotstabletypeset[
outfile=table.tex,
begin table={\begin{longtabu} to 0.6\linewidth},
end table={\end{longtabu}},
every head row/.style={
before row={
\toprule
},
after row={
% Specify units in header
& unit & unit & unit & unit & unit & unit \\
\midrule},
},
every last row/.style={
after row={
\bottomrule
\caption[short]{long}\\
\label{tab:table}\\
}
},
multicolumn names,
col sep=space,
columns={
new,
[index]0,
[index]1,
[index]2,
[index]3,
[index]4,
[index]5
},
% Index
display columns/0/.style={
column name=Index,
column type={r},
precision=1
},
display columns/1/.style={
column name=$x_1$,
column type={S},string type},
display columns/2/.style={
column name=$x_2$,
column type={S},string type},
display columns/3/.style={
column name=$x_3$,
column type={S},string type},
display columns/4/.style={
column name=$x_4$,
column type={S},string type},
display columns/5/.style={
column name=$x_5$,
column type={S},string type},
display columns/6/.style={
column name=$x_5$,
column type={S},string type}
]{DATA.txt}
\end{document}
备注:我的数据文件DATA.txt
已正确加载,并包含一些行,例如
1 2 3 4 5 6
答案1
“使示例可编译”意味着使用filecontents
或内联表。
在给定的示例中,有很多东西可以捆绑在一起。如果您有 x 次相同的命令定义,请寻找压缩它们的方法 - 这是 LaTeX,而不是 Word...
% arara: pdflatex
% arara: pdflatex
% arara: pdflatex
\RequirePackage{filecontents}
\begin{filecontents}{\jobname.txt}
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
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3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
\end{filecontents}
\documentclass[]{scrreprt}
\usepackage{pgfplotstable}
\usepackage{tabu}
\usepackage{longtable}
\usepackage{booktabs}
%\usepackage{array}
%\usepackage{caption}
%\usepackage{siunitx}
% Specify columns
\pgfplotsinvokeforeach{0,...,5} {%
\pgfplotstableset{
columns/#1/.style = {
column name=$x_{\pgfmathparse{int(#1+1)} \pgfmathresult}$,
%column type=r,
%column type={S},
string type
},
}}%
% Indices of rows:
\pgfplotstableset{
create on use/IndexCol/.style = {create col/expr={\pgfplotstablerow+1}},
columns/IndexCol/.style={column type=c},
column name={Index}
}
% Sepcify Long Table
\pgfplotstableset{
LongTable/.style 2 args={%%%%%%%%%%%%%%%%
begin table={\begin{longtabu} to 0.6\textwidth},
end table={\end{longtabu}},
every head row/.style={
before row={
\caption{#2}\\
\endfirsthead
\midrule
\multicolumn{\ColsNo}{c}{{Table \thetable\ Continued from previous page}} \\
\bottomrule
\endhead
\midrule \multicolumn{\ColsNo}{r}{Continued on next page} \\ \bottomrule
\endfoot
\midrule
\multicolumn{\ColsNo}{r}{{End of Table \thetable}} \\ \bottomrule
\endlastfoot
},
after row={& #1 \\ \midrule},
},
%every last row/.style={after row={}},
%multicolumn names,
}%%%%%%%%%%%%%%
}
\begin{document}
\chapter{My long table}
\pgfplotstablegetcolsof{\jobname.txt}
\pgfmathtruncatemacro\ColsNo{\pgfplotsretval+1}
\pgfplotstabletypeset[columns={IndexCol,0,1,...,5},
LongTable={
{{[unit]} & {[unit]} & {[unit]} & {[unit]} & {[unit]} & {[unit]}}%
{Long Table with Data \label{tab:DataTable}}%
},
outfile=table.tex,
]{\jobname.txt}
\end{document}