[Tex/LaTex] How to right align columns but center align header row using pgfplotstable

horizontal alignmentpgfplotstabletables

I am a newbie with pgfplotstable: I would like to right align the columns of the table containing my data, but keep the headers center-aligned. Here is the code for the tables – does anyone know how to modify it to accomplish this?

\begin{table}[H]
\centering
\caption{Stuff}
\pgfplotstabletypeset[
col sep=comma,
string type,
every head row/.style={before row=\hline,after row=\hline},
every last row/.style={after row=\hline},
display columns/0/.style={column name=Years, column type = {r}},
display columns/1/.style={column name = Data1, column type = {r}},
display columns/2/.style={column name = Data2, column type = {r}}
]{./DataOutput/Resids/Stuff.csv}
\end{table}

Thanks very much for any assistance.

Best Answer

To get different alignments in some cells of a tabular, you can wrap the cells in a \multicolumn (see Change alignment for individual table rows). PGFPlotstable provides a key for doing this automatically for the header row using the key multicolumn names, which takes an optional argument for the alignment. multicolumn names=l would left-align the header, for instance. The default is c, which centers the text:

\documentclass{article}
\usepackage{pgfplotstable}
\begin{document}
\begin{table}[H]
\centering
\caption{Stuff}
\pgfplotstabletypeset[
col sep=comma,
string type,
every head row/.style={before row=\hline,after row=\hline},
every last row/.style={after row=\hline},
display columns/0/.style={column name = Years, column type = {r}},
display columns/1/.style={column name = Data1, column type = {r}},
display columns/2/.style={column name = Data2, column type = {r}},
multicolumn names
]{
A, B, C
DDDDD, EEEEEEE, FFFFFFF
GGGG, HH, III
}
\end{table}
\end{document}