2

I am trying to get the rightmost header to be centered with the numbers in its column. From the MWE below, my table compiles with the rightmost header skewed to the right.

Can you help me center align the rightmost header to the numbers in its column so that it will be consistent with the other three entries of the table?

Here is the code:

\documentclass{book}
\usepackage[top=3cm,bottom=3cm,left=3.2cm,right=3.2cm,headsep=10pt,a4paper]{geometry}
\usepackage{pgfplotstable, booktabs}
\pgfplotsset{compat=newest}
\usepackage{longtable}
\usepackage{amsmath}
\usepackage{array}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}

\usepackage{filecontents}
\begin{filecontents}{TABDAT1.txt}
c   G(c)GTOT    GhatGTOT    MODELPERFORM
0.994680851 0.067915691 0.067915691 1
0.989361702 0.135831382 0.114754098 0.844827586
0.984042553 0.18735363  0.182669789 0.975
0.978723404 0.234192037 0.201405152 0.86
0.973404255 0.271662763 0.227166276 0.836206897
0.968085106 0.306791569 0.255269321 0.832061069
0.962765957 0.339578454 0.306791569 0.903448276
\end{filecontents}

\begin{document}


%%% Code from Dr. Christian ------ for not using headers.----------------------
\pgfkeysifdefined{/pgfplots/table/output empty row/.@cmd}{
    % upcoming releases offer this more convenient option:
    \pgfplotstableset{
        empty header/.style={
          every head row/.style={output empty row},
          outfile=pgfplotstable.example1.out.tex,
        }
    }
}{
    % versions up to and including 1.5.1 need this:
    \pgfplotstableset{
        empty header/.style={
            typeset cell/.append code={%
                \ifnum\pgfplotstablerow=-1 %
                    \pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
                \fi
            }
        }
    }
}

\noindent
{\scriptsize
\pgfplotstabletypeset[col sep=space,empty header,
columns={c,G(c)GTOT,GhatGTOT,MODELPERFORM},      % display specified columns
begin table=\begin{longtable},
end table=\end{longtable},
columns/c/.style={column type={c},dec sep align,precision=4,fixed,fixed zerofill},
columns/G(c)GTOT/.style={column type={c},dec sep align,precision=4,fixed,fixed zerofill},
columns/GhatGTOT/.style={column type={c},dec sep align,precision=4,fixed,fixed zerofill},
columns/MODELPERFORM/.style={column type={c},dec sep align,precision=4,fixed,fixed zerofill},
every head row/.append style={before row={%
    \caption{This is a Table with Data}%
    \label{tab:DataTable}\\\toprule
    \multicolumn{2}{c}{\emph{c}} & \multicolumn{2}{c}{$\dfrac{G(c)}{G_{TOT}}$} & \multicolumn{2}{c}{$\dfrac{\hat{G}(c)}{G_{TOT}}$} & \multicolumn{2}{c}{$\phi(c)$} \\[7pt] \toprule
    \endfirsthead
    %
    \multicolumn{8}{c}%
    {{\bfseries Table \thetable\ Continued from previous page}} \\
    \toprule
    %
    \multicolumn{2}{c}{\emph{c}} & \multicolumn{2}{c}{$\dfrac{G(c)}{G_{TOT}}$} & \multicolumn{2}{c}{$\dfrac{\hat{G}(c)}{G_{TOT}}$} & \multicolumn{2}{c}{$\phi(c)$} \\[7pt] \toprule
    \endhead
    %
    \midrule \multicolumn{8}{r}{{Continued on next page}} \\ \bottomrule
    \endfoot
    %
    \midrule
    \multicolumn{8}{r}{{End of Table}} \\ \bottomrule
    \endlastfoot
    }},
]{TABDAT1.txt}

\end{document} 
  • 1
    The problem is unrelated to pgfplotstable. Your intermediate head Table \thetable\ Continued from previous page} is longer than four decimal columns, so the extra space needed is added to the last column. – gernot says Reinstate Monica Apr 2 '17 at 10:23
  • 1
    Unrelated: There is a closing brace missing, to end {\scriptsize. Moreover, replace \emph{c} by $c$. – gernot says Reinstate Monica Apr 2 '17 at 10:24