尝试使用 pgfplotstable 创建表格,但当我想写希腊字母时出现错误(实际上,任何以“\”开头的数学模式符号)。在“a”和“b”中,我希望有一个 alpha 和一个 beta。你能帮助我吗?
这是我的代码:
\documentclass{article}
\usepackage{xcolor}
\usepackage{booktabs,colortbl,pgfplotstable}
\definecolor{rulecolor}{RGB}{0,71,171}
\definecolor{tableheadcolor}{gray}{0.92}
\newcommand{\topline}{ %
\arrayrulecolor{rulecolor}\specialrule{0.1em}{\abovetopsep}{0pt}%
\arrayrulecolor{tableheadcolor}\specialrule{\belowrulesep}{0pt}{0pt}%
\arrayrulecolor{rulecolor}}
\newcommand{\midtopline}{ %
\arrayrulecolor{tableheadcolor}\specialrule{\aboverulesep}{0pt}{0pt}%
\arrayrulecolor{rulecolor}\specialrule{\lightrulewidth}{0pt}{0pt}%
\arrayrulecolor{white}\specialrule{\belowrulesep}{0pt}{0pt}%
\arrayrulecolor{rulecolor}}
\newcommand{\bottomline}{ %
\arrayrulecolor{white}\specialrule{\aboverulesep}{0pt}{0pt}%
\arrayrulecolor{rulecolor} %
\specialrule{\heavyrulewidth}{0pt}{\belowbottomsep}}%
\newcommand{\midheader}[2]{%
\midrule\topmidheader{#1}{#2}}
\newcommand\topmidheader[2]{\multicolumn{#1}{c}{\textsc{#2}}\\%
\addlinespace[0.5ex]}
\pgfplotstableset{mystyle/.style ={%
header=true,
string type,
column type=c,
every odd row/.style={
before row=
},
every first column/.style={
column type=l
},
every head row/.style={
before row={\topline\rowcolor{tableheadcolor}},
after row={\midtopline},
},
every last row/.style={
after row=\bottomline
},
col sep=&,
row sep=\\
}
}
\begin{document}
\begin{table}
\centering
\pgfplotstabletypeset[mystyle]{
{$ $} & {$a$} & {$b$} \\
{0} & {10} & {$1000$}\\
}
\end{table}
\end{document}
答案1
正如 Zarko 所说,手册第 17-18 页显示的示例pgfplotstable
使用了解决问题的其中一种可能的方法。
所使用的格式在同一手册第 11 页末尾有所解释:
columns/{lowlevel colname}/.style={column name = display column name}
此处,低级列名是指输入表中存在的列名。此低级列名有几个限制(例如,它必须是可扩展的 - 这意味着禁止使用许多控制序列)。列名的值仅在用于\pgfplotstabletypeset
为相关列生成显示名称时使用。
我已将您问题的解决方案和编译后得到的结果包含在内。您可以在 中找到我的[< options >]
修改\pgfplotstabletypeset
。
\documentclass{article}
\usepackage{xcolor}
\usepackage{booktabs,colortbl,pgfplotstable}
\definecolor{rulecolor}{RGB}{0,71,171}
\definecolor{tableheadcolor}{gray}{0.92}
\newcommand{\topline}{ %
\arrayrulecolor{rulecolor}\specialrule{0.1em}{\abovetopsep}{0pt}%
\arrayrulecolor{tableheadcolor}\specialrule{\belowrulesep}{0pt}{0pt}%
\arrayrulecolor{rulecolor}}
\newcommand{\midtopline}{ %
\arrayrulecolor{tableheadcolor}\specialrule{\aboverulesep}{0pt}{0pt}%
\arrayrulecolor{rulecolor}\specialrule{\lightrulewidth}{0pt}{0pt}%
\arrayrulecolor{white}\specialrule{\belowrulesep}{0pt}{0pt}%
\arrayrulecolor{rulecolor}}
\newcommand{\bottomline}{ %
\arrayrulecolor{white}\specialrule{\aboverulesep}{0pt}{0pt}%
\arrayrulecolor{rulecolor} %
\specialrule{\heavyrulewidth}{0pt}{\belowbottomsep}}%
\newcommand{\midheader}[2]{%
\midrule\topmidheader{#1}{#2}}
\newcommand\topmidheader[2]{\multicolumn{#1}{c}{\textsc{#2}}\\%
\addlinespace[0.5ex]}
\pgfplotstableset{mystyle/.style ={%
header=true,
string type,
column type=c,
every odd row/.style={
before row=
},
every first column/.style={
column type=l
},
every head row/.style={
before row={\topline\rowcolor{tableheadcolor}},
after row={\midtopline},
},
every last row/.style={
after row=\bottomline
},
col sep=&,
row sep=\\
}
}
\begin{document}
\begin{table}
\centering
\pgfplotstabletypeset[mystyle,
columns/a/.style={column name=$\alpha$},
columns/b/.style={column name=$\beta$},
]{
{$ $} & {a} & {b} \\
{0} & {10} & {$1000$}\\
}
\end{table}
\end{document}