TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm a new user of TikZ pgfplots and pgfplotstable and have been stoked to discover how easy it is to go between Matlab (via matlab2tikz and writing to CSV) and LaTeX. I'm getting a little more ambitious now, and my question is, how do I properly implement a multi-page longtable together with pgfplotstableset inside a float (for placement, captioning, etc..)? So far I've been able to avoid this complication by splitting up these long lists into shorter subtables. I've also tried a couple of work-arounds to try to achieve the desired functionality, including adding captions to the end table alias as suggested in the pgfplots Manual or using the capt-of package to add a caption outside of a float. This works reasonably well but doesn't have the nice "Table ? continued" behavior of 'longtable'. Is there a better way to do this?

Here is a typical macro, the input arguments #1 are a CSV filename, and #2 a caption for the ToC/LoF:

begin table=\begin{longtable},
end table=\caption{#2}\end{longtable}
} % similar to manual for package pgfplotstable

\pgfplotstableset{columns/Channel/.style={string type}}
\pgfplotstableset{columns/Units/.style={string type}}
\pgfplotstableset{columns/Description/.style={string type,column type={p{6cm}}}}
\pgfplotstableread[col sep=comma]{#1}\strtable
%\begin{longtable} % this bombs
%\captionof{table}{#2} % alternative way to try to get a caption in there using capt-of package
every first column/.style={string type,column type={@{}l|}},
    every even row/.style={before row={\rowcolor[gray]{0.9}}},
    every head row/.style={before row=\toprule,after row=\midrule\endhead}, % repeats header
    every last row/.style={after row=\bottomrule},
    % \end{longtable} % bombs
share|improve this question
Welcome to TeX.sx! You don't have to sign with your name since it automatically appears in the lower right corner of your post. – Werner Feb 21 '12 at 18:56

I experimented a while and found that

begin table=\begin{longtable},
every first row/.append style={before row={%
    \caption{The caption}%
    \multicolumn{3}{c}{{\bfseries \tablename\ \thetable{} -- continued from previous page}} \\
end table=\end{longtable}
} % similar to manual for package pgfplotstable

works well. Add debug to the option list to see the generated output listing in your log file. It seems as if the \endfirsthead and endhead macros collect the previously entered lines as templates and replicate them at the designated positions (compare the longtable manual for details).

The only special thing is to add these items to the correct place in pgfplotstable -- here, I used every first row/.append style={before row={}} as tool to inject the statements. Note that the \multicolumn statement needs the number of columns.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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