有人知道为什么这不起作用吗?我试图在图表中添加水平线,但它在\midrule
命令下中断了
\documentclass{article}
\usepackage{etoolbox}
\usepackage{pgfplotstable}
\usepackage{pgfplots}
\usepackage{booktabs}
\begin{filecontents*}{test.csv}
ColA, ColB, ColC
0.17, 0.91, 0.67
0.15, 0.17, 0.92
0.48, 0.1, 0.28
\end{filecontents*}
\def\buildTable#1{%
\pgfplotstableread[col sep = comma]{#1}\rawdata%
\xdef\theTable{\noexpand\pgfplotstabletypeset[every row/.style={before row=\midrule}]}%
\theTable{\rawdata}%
}%
\begin{document}
\begin{table}
\buildTable
{%CSV file
test.csv%
}
\end{table}
\end{document}
答案1
如果你真的想\midrule
在每一行之前使用简单的before row
键
\documentclass{article}
\usepackage{etoolbox}
\usepackage{pgfplotstable}
\usepackage{pgfplots}
\usepackage{booktabs}
\begin{filecontents*}{test.csv}
ColA, ColB, ColC
0.17, 0.91, 0.67
0.15, 0.17, 0.92
0.48, 0.1, 0.28
\end{filecontents*}
\def\buildTable#1{%
\pgfplotstableread[col sep = comma]{#1}\rawdata%
\pgfplotstabletypeset[before row= \midrule]\rawdata
}%
\begin{document}
\begin{table}
\buildTable
{%CSV file
test.csv%
}
\end{table}
\end{document}
答案2
我不知道为什么代码会通过\xdef
和绕道而行\TheTable
。但我会在 里面使用\noexpand
before 。\midrule
\xdef
另外,我没有every row
在文档中找到这种样式,但every head row
它确实存在:
\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\pgfplotsset{compat=newest}
\begin{filecontents*}{test.csv}
ColA, ColB, ColC
0.17, 0.91, 0.67
0.15, 0.17, 0.92
0.48, 0.1, 0.28
\end{filecontents*}
\newcommand{\buildTable}[1]{%
\pgfplotstableread[col sep = comma]{#1}\rawdata
\xdef\theTable{%
\noexpand\pgfplotstabletypeset[
every head row/.style={after row=\noexpand\midrule}%
]}%
\theTable{\rawdata}%
}
\begin{document}
\begin{table}
\buildTable
{%CSV file
test.csv%
}
\end{table}
\end{document}
按小数点分隔符对齐:
\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}
\begin{filecontents*}{test.csv}
ColA, ColB, ColC
0.17, 0.91, 0.67
0.15, 0.17, 0.92
0.48, 0.1, 0.28
\end{filecontents*}
\newcommand{\buildTable}[1]{%
\pgfplotstableread[col sep = comma]{#1}\rawdata
\xdef\theTable{%
\noexpand\pgfplotstabletypeset[
dec sep align={c},
every head row/.style={after row=\noexpand\midrule}%
]}%
\theTable{\rawdata}%
}%
\begin{document}
\begin{table}
\buildTable
{%CSV file
test.csv%
}
\end{table}
\end{document}