18

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.

0

1 Answer 1

13

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}
4
  • Thank you very much for your thorough and helpful answer. Jul 17, 2013 at 17:58
  • Pleasure! Please consider upvoting the answer by clicking the triangle next to it. If you consider your problem solved, you can also click the tick mark.
    – Jake
    Jul 17, 2013 at 18:04
  • If a column is formated via dec sep align, the multicolumn names assignment does not have any effect. Maybe you know a solution for fixing this?
    – maetra
    Mar 27, 2014 at 18:25
  • Great answer. Newbie comment in passing, instead of display columns/0/.style= I was able to get the same effect with columns/myColumnName/.append style = {column type = {r}}, where I refer to the column by its name rather than the index.
    – PatrickT
    Mar 3, 2018 at 13:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .