从包含混合字符串和数字的文件中读取表格

从包含混合字符串和数字的文件中读取表格

我正在生成一个以逗号分隔值的文件,我需要在表格中显示其内容。有些列需要数学模式,因为我在其中放置了变量名。

以下是我遇到的问题的 MWE:

\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}

看起来它没有正确地分隔列。你能发现错误吗?谢谢!

在此处输入图片描述

答案1

您正在使用的问题似乎存在dec sep align- 如果没有它,我会得到: 桌子

为了使内容正确对齐,dec sep align仅添加数字列:

\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}

对齐表

如果你还想在小数点对齐后将内容居中对齐,则需要采取类似以下方法建议在这里看起来像这样:

\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}

居中对齐表格

相关内容