5

I want to print a long table with pgfplotstable and long tabu. For some reason, with the following code, I do not get the header repeated on every page. I also want a \bottomrule and a caption on every page like "table xy (continued)".

Also, the width I specified by \begin{tabu} to 0.6\linewidth is ignored.

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

Remark: My data file DATA.txt is loaded correctly and contains some lines like

1 2 3 4 5 6
  • 1
    Can you make your example compilable? – Symbol 1 Nov 29 '16 at 2:11
  • Sorry for the extreme delay. I fixed it by adding two packages I forgot when copying out of my document: \usepackage{siunitx}, \usepackage{caption}. Also added \\ in every last row/.style={...} to the \caption and \label command. – Christoph90 Jul 25 '17 at 9:06
2

"making the example compilable" means using filecontents or an inline table.

In the given example are much things which can be bunched together. If you have x-times the same command definitions, look for ways to compress them - this is LaTeX, not Word...

enter image description here

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.