2

I'm generating a file with comma separated values and I need to display its contents in a table. Some columns need math mode as I placed variable names in there.

Here is a MWE with my problem:

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{pgfplotstable}
\usepackage{booktabs}

\pgfplotstableread[col sep=comma]{
ParameterC,Cellobiose,ParameterG,Glucose,ParameterXo,Xylooligomers,ParameterX,Xylose,ParameterpH,pH,Parametermu,Viscosity
E_{M_C}^{G},0.500462577695772,\alpha_C^{G},0.595034931903454,E_{M_C}^{E},0.467132253228601,K_{A_C}^{G},0.45836079026922,K_{A_C}^{G},0.937036239950334,E_{M_C}^{E},0.831652617418096
\alpha_C^{E},0.496153968086408,a_2,0.59421878635291,K_4,0.462469172623973,E_{M_C}^{E},0.448945933959748,E_{M_C}^{G},0.159665534055731,I_{G_1},0.393938611208751
I_{X_2},0.459441172005239,K_{A_C}^{E},0.21747820438974,K_{A_C}^{E},0.446548053467089,\alpha_C^{G},0.319585127620579,\alpha_X^{E},0.15522878340942,I_{G_2},0.304112048191325
I_{C_4},0.457702457871354,E_{M_C}^{G},0.192527945825199,\alpha_C^{E},0.445734897595437,K_{A_X}^{X},0.306668962811058,I_{G_4},0.114115162076442,K_{A_C}^{G},0.273157552479744
K_{A_X}^{X},0.0813359759834273,K_{A_X}^{X},0.163396355621483,I_{G_1},0.200244546104448,I_{X_2},0.30012367397621,I_{C_2},0.104368068024314,K_3,0.15774123515272
}\loadTestTable

\begin{document}
\begin{table}[htbp]
    \pgfkeys{/pgf/number format/.cd,fixed relative,precision=2}
    \small
    \begin{center}
        \caption{SRC coefficients.}
        \label{table1}
        \pgfplotstabletypeset[
            col sep=comma, % the seperator in our .csv file
            dec sep align,
            skip rows between index={20}{\pgfplotstablerows},
            math/.style={%
                preproc cell content/.append style={/pgfplots/table/@cell content/.add={$}{$}},
            },
            columns/ParameterC/.style={string type, column name={$\theta$}, math},
            columns/ParameterG/.style={string type, column name={$\theta$}, math},
            columns/ParameterXo/.style={string type, column name={$\theta$}, math},
            columns/ParameterX/.style={string type, column name={$\theta$}, math},
            columns/ParameterpH/.style={string type, column name={$\theta$}, math},
            columns/Parametermu/.style={string type, column name={$\theta$}, math},
            every head row/.style={
                before row={\toprule}, % have a rule at top
                after row={\midrule}},
            every last row/.style={after row={\bottomrule}} % rule at bottom
        ]{\loadTestTable}
    \end{center}
\end{table}
\end{document}

It looks like it's not separating the columns correctly. Can you spot the error? Thanks!

enter image description here

remus
  • 3,093
  • It's dec sep align which causes the wrong display. How do I use dec sep align only for the non string columns? – remus Aug 27 '14 at 08:38

1 Answers1

2

Seems to be a problem with the dec sep align you're using - without it I get: table

To have things aligned properly, add dec sep align for the numerical columns only:

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{pgfplotstable}
\usepackage{booktabs}

\pgfplotstableread[col sep=comma]{
ParameterC,Cellobiose,ParameterG,Glucose,ParameterXo,Xylooligomers,ParameterX,Xylose,ParameterpH,pH,Parametermu,Viscosity
E_{M_C}^{G},0.500462577695772,\alpha_C^{G},0.595034931903454,E_{M_C}^{E},0.467132253228601,K_{A_C}^{G},0.45836079026922,K_{A_C}^{G},0.937036239950334,E_{M_C}^{E},0.831652617418096
\alpha_C^{E},0.496153968086408,a_2,0.59421878635291,K_4,0.462469172623973,E_{M_C}^{E},0.448945933959748,E_{M_C}^{G},0.159665534055731,I_{G_1},0.393938611208751
I_{X_2},0.459441172005239,K_{A_C}^{E},0.21747820438974,K_{A_C}^{E},0.446548053467089,\alpha_C^{G},0.319585127620579,\alpha_X^{E},0.15522878340942,I_{G_2},0.304112048191325
I_{C_4},0.457702457871354,E_{M_C}^{G},0.192527945825199,\alpha_C^{E},0.445734897595437,K_{A_X}^{X},0.306668962811058,I_{G_4},0.114115162076442,K_{A_C}^{G},0.273157552479744
K_{A_X}^{X},0.0813359759834273,K_{A_X}^{X},0.163396355621483,I_{G_1},0.200244546104448,I_{X_2},0.30012367397621,I_{C_2},0.104368068024314,K_3,0.15774123515272
}\loadTestTable

\begin{document}
\begin{table}[htbp]
    \pgfkeys{/pgf/number format/.cd,fixed relative,precision=2}
    \small
    \begin{center}
        \caption{SRC coefficients.}
        \label{table1}
        \pgfplotstabletypeset[
            col sep=comma, % the seperator in our .csv file
%            dec sep align,
            skip rows between index={20}{\pgfplotstablerows},
            math/.style={%
                preproc cell content/.append style={/pgfplots/table/@cell content/.add={$}{$}},
            },
            columns/ParameterC/.style={string type, column name={$\theta$}, math},
            columns/ParameterG/.style={string type, column name={$\theta$}, math},
            columns/ParameterXo/.style={string type, column name={$\theta$}, math},
            columns/ParameterX/.style={string type, column name={$\theta$}, math},
            columns/ParameterpH/.style={string type, column name={$\theta$}, math},
            columns/Parametermu/.style={string type, column name={$\theta$}, math},
            columns/Cellobiose/.style={dec sep align},
            columns/Glucose/.style={dec sep align},
            columns/Xylooligomers/.style={dec sep align},
            columns/Xylose/.style={dec sep align},
            columns/pH/.style={dec sep align},
            columns/Viscosity/.style={dec sep align},
            every head row/.style={
                before row={\toprule}, % have a rule at top
                after row={\midrule}},
            every last row/.style={after row={\bottomrule}} % rule at bottom
        ]{\loadTestTable}
    \end{center}
\end{table}
\end{document}

aligned table

If additionally you want to center align things after aligning on the decimal separator, you'll need to resort to something like suggested here and looking like this:

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{siunitx}
\sisetup{round-mode = figures, round-precision = 2}


\pgfplotstableread[col sep=comma]{
ParameterC,Cellobiose,ParameterG,Glucose,ParameterXo,Xylooligomers,ParameterX,Xylose,ParameterpH,pH,Parametermu,Viscosity
E_{M_C}^{G},0.500462577695772,\alpha_C^{G},0.595034931903454,E_{M_C}^{E},0.467132253228601,K_{A_C}^{G},0.45836079026922,K_{A_C}^{G},0.937036239950334,E_{M_C}^{E},0.831652617418096
\alpha_C^{E},0.496153968086408,a_2,0.59421878635291,K_4,0.462469172623973,E_{M_C}^{E},0.448945933959748,E_{M_C}^{G},0.159665534055731,I_{G_1},0.393938611208751
I_{X_2},0.459441172005239,K_{A_C}^{E},0.21747820438974,K_{A_C}^{E},0.446548053467089,\alpha_C^{G},0.319585127620579,\alpha_X^{E},0.15522878340942,I_{G_2},0.304112048191325
I_{C_4},0.457702457871354,E_{M_C}^{G},0.192527945825199,\alpha_C^{E},0.445734897595437,K_{A_X}^{X},0.306668962811058,I_{G_4},0.114115162076442,K_{A_C}^{G},0.273157552479744
K_{A_X}^{X},0.0813359759834273,K_{A_X}^{X},0.163396355621483,I_{G_1},0.200244546104448,I_{X_2},0.30012367397621,I_{C_2},0.104368068024314,K_3,0.15774123515272
}\loadTestTable

\begin{document}
\begin{table}[htbp]
    \pgfkeys{/pgf/number format/.cd,fixed relative,precision=2}
    \small
    \begin{center}
        \caption{SRC coefficients.}
        \label{table1}
        \pgfplotstabletypeset[
            col sep=comma, % the seperator in our .csv file
%            dec sep align,
            skip rows between index={20}{\pgfplotstablerows},
            math/.style={%
                preproc cell content/.append style={/pgfplots/table/@cell content/.add={$}{$}},
            },
            assign column name/.code=\pgfkeyssetvalue{/pgfplots/table/column name}{{{#1}}},
            columns/ParameterC/.style={string type, column name={$\theta$}, math},
            columns/ParameterG/.style={string type, column name={$\theta$}, math},
            columns/ParameterXo/.style={string type, column name={$\theta$}, math},
            columns/ParameterX/.style={string type, column name={$\theta$}, math},
            columns/ParameterpH/.style={string type, column name={$\theta$}, math},
            columns/Parametermu/.style={string type, column name={$\theta$}, math},
            columns/Cellobiose/.style={assign column name={Cellobiose}, column type={S[]}, string type},
            columns/Glucose/.style={assign column name={Glucose}, column type={S[]}, string type},
            columns/Xylooligomers/.style={assign column name={Xylooligomers}, column type={S[]}, string type},
            columns/Xylose/.style={assign column name={Xylose}, column type={S[]}, string type},
            columns/pH/.style={assign column name={pH}, column type={S[]}, string type},
            columns/Viscosity/.style={assign column name={Viscosity}, column type={S[]}, string type},
            every head row/.style={
                before row={\toprule}, % have a rule at top
                after row={\midrule}},
            every last row/.style={after row={\bottomrule}} % rule at bottom
        ]{\loadTestTable}
    \end{center}
\end{table}
\end{document}

center aligned table

greyshade
  • 3,576
  • @remus since you had center aligning in your original example, I expanded my answer with center and decimal sep aligned columns. – greyshade Aug 27 '14 at 09:04
  • Many thanks! Do you also know how to increase the space between rows (globally per table)? I'm using superscripts and subscripts and they look a bit too close to each other. – remus Aug 27 '14 at 13:08
  • 1
    try \renewcommand{\arraystretch}{1.25} - and fit the actual factor to your liking. note that this is global to the document unless you encapsulate your table (and the \renewcommand) in a group, e.g. with \begingroup...\endgroup or simply {...}. – greyshade Aug 27 '14 at 13:14