Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

pgfplotstable seems ideal for incorporating CSV data into a table automatically. I'm however having trouble with lines (they won't merge with headers, and I can't seem to get them to work at the bottom of my table).

MWE:

\documentclass[10pt,a4paper]{article}
\usepackage[utf8x]{inputenc}
\usepackage{ucs}
\usepackage[english]{babel}

\begin{filecontents*}{xpoweredby-trunc.csv}
X-Powered-By 2011-07 Perc1 2012-06 Perc2 2012-11 Perc3
PHP 7354 48.1 6225 43.75 7484 54.02
ASP.NET 12 0.08 37 0.26 5587 40.32
PleskLin 10 0.07 283 1.99 202 1.46
W3 69 0.45 137 0.96 186 1.34
UrlRewriter.NET 0 0 0 0 73 0.53
PleskWin 0 0 0 0 72 0.52
Servlet 135 0.88 110 0.77 81 0.58
Phusion 39 0.26 37 0.26 41 0.3
\end{filecontents*}

\usepackage{pgfplotstable}
\begin{document}
{\footnotesize
\pgfplotstabletypeset[
every head row/.style={
before row=\caption{X-Powered-By header}\\\toprule, after row=\bottomrule \endhead
% as in the previous example, this patches the first row:
before row={
\hline
},
after row=\hline,
},
every even row/.style={
before row={\rowcolor[gray]{0.92}}},
columns/X-Powered-By/.style={string type, column type=|r},
columns/2011-07/.style={numeric type, column type=||r},
columns/Perc1/.style={/pgf/number format/fixed, numeric type, column type=r||, column name=\% },
columns/2012-06/.style={numeric type, column type=r},
columns/Perc2/.style={/pgf/number format/fixed, numeric type, column type=r||, column name=\%},
columns/2012-11/.style={numeric type, column type=r},
columns/Perc3/.style={/pgf/number format/fixed, numeric type, column type=r|, column name=\%},
]{xpoweredby-trunc.csv}
} % footnotesize ends
\end{document}

The example currently generates: Currently

I want it to also:

  • have the toprule merge with the lines in the header - currently it seems to be floating
  • have the bottom of the table close - also with merging, non-floaty lines

I know this table is far from Tufte-ian, but is required as such by style guidelines for the conference.

Is there something I am missing as to how the line/rules should be defined?

share|improve this question

2 Answers 2

I think you get much closer to what you expect if you insert the missing comma right before % as in the previous example. Apparently, the stuff which follows it has been included into the cell but did not make it into the output.

Your example does not compile as-is; I assume that you meant to include booktabs, colortbl, and longtable.

This here is what I got so far:

\documentclass[10pt,a4paper]{article}
\usepackage[utf8x]{inputenc}
\usepackage{ucs}
\usepackage[english]{babel}

\usepackage{longtable}
\usepackage{booktabs}
\usepackage{colortbl}

\begin{filecontents*}{xpoweredby-trunc.csv}
X-Powered-By 2011-07 Perc1 2012-06 Perc2 2012-11 Perc3
PHP 7354 48.1 6225 43.75 7484 54.02
ASP.NET 12 0.08 37 0.26 5587 40.32
PleskLin 10 0.07 283 1.99 202 1.46
W3 69 0.45 137 0.96 186 1.34
UrlRewriter.NET 0 0 0 0 73 0.53
PleskWin 0 0 0 0 72 0.52
Servlet 135 0.88 110 0.77 81 0.58
Phusion 39 0.26 37 0.26 41 0.3
\end{filecontents*}

\usepackage{pgfplotstable}
\begin{document}
{\footnotesize
    \pgfplotstabletypeset[
        begin table=\begin{longtable}, % -------- CF
        end table=\end{longtable},
        every head row/.style={
            %before row=\caption{X-Powered-By header}\\\toprule, after row=\bottomrule \endhead,% --------- CF
            % as in the previous example, this patches the first row:
            before row={\hline},
            after row=\hline,
        },
        every last row/.style={% ------------ CF
            after row=\hline,
        },
        every even row/.style={
        before row={\rowcolor[gray]{0.92}}},
        columns/X-Powered-By/.style={string type, column type=|r},
        columns/2011-07/.style={numeric type, column type=||r},
        columns/Perc1/.style={/pgf/number format/fixed, numeric type, column type=r||, column name=\% },
        columns/2012-06/.style={numeric type, column type=r},
        columns/Perc2/.style={/pgf/number format/fixed, numeric type, column type=r||, column name=\%},
        columns/2012-11/.style={numeric type, column type=r},
        columns/Perc3/.style={/pgf/number format/fixed, numeric type, column type=r|, column name=\%},
    ]{xpoweredby-trunc.csv}
} % footnotesize ends
\end{document}

enter image description here

This solution does not use booktabs anymore - I uncommented your first attempt with the toprule.

Perhaps some expert for table typesetting can tell you how to tweak booktabs. You may also want to search for input of how to modify the vertical size of the head row.

Note that you can add the debug option to see the generated output - that might simplify the experiments because you can directly work with pure LaTeX code.

share|improve this answer
    
Great that works perfectly. I'll have to spend a lot more time on getting my head around this, but it seems the best way to go is progressive enhancement rather than using existing examples. Any suggestions (best practice) for where the caption should go? Thanks. –  Forkrul Assail Dec 9 '12 at 23:08

In general it does not make sense (but induce much pain) to use booktab tables with vertical lines. Also, coloring booktab tables is not entirely trivial. One can play around with the additional spaces booktabs defines which is documented in the manual see \heavyrulewidth, \aboverulesep etc. By using and partially redefining them one can achieve something like below, but it was no fun (I am no Latex expert though and there were a number of other problems involved). table of pain
If needed, I can try to extract the most important bits, but I have not tested this with pgfplotstable at all.

share|improve this answer

Your Answer

 
discard

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.