pgfplotstable,多列 sp

pgfplotstable,多列 sp

我正在尝试制作一个表格(代码如下),该表格应包含三个标题和五个等距的子列,但最右边的子列却不同意。如果我将很长的标题放在多行上,那么一切都会很整洁,但我宁愿有一个间距合适的宽表格。

\documentclass[[a4paper,12pt]{article}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\begin{document}
\begin{table}
\centering
\caption{Multicolumn Table}
\pgfplotstabletypeset[
header=false,
every head row/.style={after row={\toprule\toprule \multicolumn{1}{c}{C} &     \multicolumn{1}{c}{B} & \multicolumn{3}{c}{A very Long Heading On One Line}\\}},
every first row/.style={after row=\midrule},
every last row/.style={after row=\bottomrule\bottomrule},
string type,
columns/0/.style={column name=},
columns/1/.style={column name=},
columns/2/.style={column name=},
columns/3/.style={column name=},
columns/4/.style={column name=},
columns/5/.style={column name=},
columns/6/.style={column name=},
col sep=comma, row sep=\\,
string type,
]{
,,d,e,f\\
1,4,2,8,1\\
5,5,5,8,6\\
2,6,4,6,2\\
3,7,5,6,5\\
9,8,3,3,3\\
7,9,1,5,1\\
7,7,4,9,2\\
6,1,3,7,7\\
2,7,1,3,8\\
7,9,5,5,7\\
9,4,6,5,7\\
Ans,,9,9,9\\
}
\end{table}

\end{document}

答案1

您可以设置列的尺寸,例如

\newcolumntype{C}{>{\centering\arraybackslash}p{2cm}}

然后C在列样式中使用:

\documentclass[a4paper,12pt]{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.18} 
\usepackage{booktabs}
\newcolumntype{C}{>{\centering\arraybackslash}p{2cm}}% a centered fixed-width-column
\begin{document}
\begin{table}
\centering
\caption{Multicolumn Table}
\pgfplotstabletypeset[
header=false,
every head row/.style={after row={\toprule\toprule \multicolumn{1}{c}{C} &     \multicolumn{1}{c}{B} & \multicolumn{3}{c}{A very Long Heading On One Line}\\}},
every first row/.style={after row=\midrule},
every last row/.style={after row=\bottomrule\bottomrule},
string type,
columns/0/.style={column type=C,column name=},
columns/1/.style={column type=C,column name=},
columns/2/.style={column type=C,column name=},
columns/3/.style={column type=C,column name=},
columns/4/.style={column type=C,column name=},
columns/5/.style={column type=C,column name=},
col sep=comma, row sep=\\,
string type,
]{
,,d,e,f\\
1,4,2,8,1\\
5,5,5,8,6\\
2,6,4,6,2\\
3,7,5,6,5\\
9,8,3,3,3\\
7,9,1,5,1\\
7,7,4,9,2\\
6,1,3,7,7\\
2,7,1,3,8\\
7,9,5,5,7\\
9,4,6,5,7\\
Ans,,9,9,9\\
}
\end{table}

\end{document}

在此处输入图片描述

相关内容