我正在使用“pgf-plots-table”从 csv 文件创建表格。多列选项用于为标题行获取不同的对齐方式。问题是,表格标题中没有垂直线,因此看起来很丑陋。
请帮忙在头行添加垂直线。
我的代码是:
\documentclass{article}
\usepackage{pgfplotstable}
\begin{filecontents*}{jobname.csv}
M,0.4,0.7,1.0,1.3
0.201,1.001,1.801,4.601,3.401
0.200,1.000,1.800,2.600,3.400
\end{filecontents*}
\begin{document}
\pgfplotstabletypeset[
multicolumn names,
col sep= comma, % the separator in our .csv file
string type, % added in hopes of enabling alphabetic input.
header=has colnames,
every head row/.style={before row=\hline, after row=\hline},
every last row/.style={after row=\hline},
column type/.add={|}{},
every last column/.style={column type/.add={}{|}},
]{jobname.csv}
\end{document}
答案1
您可以说multicolumn name={<column spec>}
确定标题中使用的列规范类型,这样就multicolumn names={l|}
几乎可以做到了,因为它将在每个标题单元格的右侧添加垂直规则。(当然,根据您的需要,l
用c
或替换。)r
但是,对于第一个单元格,您需要做更多的事情,以便在两侧添加垂直规则:
columns/M/.style={
assign column name/.style={
/pgfplots/table/column name={\multicolumn{1}{|l|}{##1}}
}
},
assign column name
可用于指定列标题的格式。因为我们只想更改第一列的格式,所以将其放在 内columns/M/.style
。
我认为您的完整表格更复杂,但看到这个特定的表格在没有垂直规则的情况下看起来更好(在我看来),所以我另外添加了一个例子。
\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\begin{filecontents*}{jobname.csv}
M,0.4,0.7,1.0,1.3
0.201,1.001,1.801,4.601,3.401
0.200,1.000,1.800,2.600,3.400
\end{filecontents*}
\begin{document}
\pgfplotstabletypeset[
multicolumn names={l|},
% display columns/0/.style={ % this line is an alternative to the next one, if you prefer to access the column by index instead of name
columns/M/.style={
assign column name/.style={
/pgfplots/table/column name={\multicolumn{1}{|l|}{##1}}
}
},
col sep= comma, % the separator in our .csv file
string type, % added in hopes of enabling alphabetic input.
header=has colnames,
every head row/.style={before row=\hline, after row=\hline},
every last row/.style={after row=\hline},
column type/.add={|}{},
every last column/.style={column type/.add={}{|}},
]{jobname.csv}
\bigskip
\pgfplotstabletypeset[
multicolumn names={l},
col sep= comma, % the separator in our .csv file
string type, % added in hopes of enabling alphabetic input.
header=has colnames,
every head row/.style={before row=\toprule, after row=\midrule},
every last row/.style={after row=\bottomrule},
]{jobname.csv}
\end{document}