我正在尝试创建具有给定形状的表格。但我无法更改列数并保持形状不变。
这是“预期”表格的图像(由 Excel 制作):
结果如下图所示:
我只需要 15 列,而不是 4 列。
这是表格的代码:
\documentclass[3p,11pt,authoryear]{elsarticle}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{epstopdf,cmap,amssymb,amsfonts,amsmath,stmaryrd,mathtext,enumerate,float,natbib,indentfirst,hyperref,graphicx,multirow,color,setspace}
% lmodern used for good quality english font rendering.
\usepackage{lmodern}
\graphicspath{{figures/en/}}
\journal{Journal Title}
\begin{document}
\section{Results}
\label{sec:Results}
\begin{table*}[!h]
\caption{Eigenvalue and variance of the components (Comp.)}
\label{tab:}
\setlength{\arrayrulewidth}{1.05 pt}
\renewcommand{\arraystretch}{1.1}
\begin{tabular*}{1.0\textwidth}{@{\extracolsep{\fill}}lrrr}
\hline
Components & \textit{C 1} & \textit{C 2} & \textit{C 3} & \textit{C 4} & \textit{C 5} & \textit{C 5} & \textit{C 6} & \textit{C 7} & \textit{C 8} & \textit{C 9} & \textit{C 10} & \textit{C 11} & \textit{C 12} & \textit{C 13} & \textit{C 14} \\
\hline
\multicolumn{15}{l}{\textit{Eigenvalue}} \\
PCA 1 & 4.76\textsuperscript{*} & 1.82\textsuperscript{*} & 1.56\textsuperscript{*} & 1.03\textsuperscript{*} & 0.92 & 0.88 & 0.88 & 0.74 & 0.49 & 0.29 & 0.25 & 0.22 & 0.17 & 0.06 \\
PCA 2 & 3.34\textsuperscript{*} & 1.72\textsuperscript{*} & 1.54\textsuperscript{*} & 1.02\textsuperscript{*} & 0.91 & 0.87 & 0.8 & 0.69 & 0.45 & 0.27 & 0.25 & 0.13 & & \\
\multicolumn{15}{l}{\textit{Percentage of variance}} \\
PCA 1 & 34 & 13 & 11.2 & 7.3 & 6.6 & 6.3 & 5.73 & 5.3 & 3.5 & 2.1 & 1.8 & 1.6 & 1.2 & 0.06 \\
PCA 2 & 27.9 & 14.4 & 12.8 & 8.5 & 7.6 & 7.3 & 6.7 & 5.8 & 3.7 & 2.3 & 2 & 1.1 & & \\
\hline
\end{tabular*}
\begin{spacing}{0.5}
{\scriptsize Note: '*' in the tabular indicate a value which can be considerate as significant.}
\end{spacing}
\end{table*}
\end{document}
答案1
使用正确的列数、S
除第一列之外的所有列的列类型、threeparttablex
表格注释和booktabs
表格规则,删除错误的双列标题\textit{C 5}
,姆韦您的表格是:
\documentclass[3p,11pt,authoryear]{elsarticle}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage[referable]{threeparttablex} % <--- for \note, \source
% lmodern used for good quality english font rendering.
\usepackage{lmodern}
\begin{document}
\begin{table*}[tb]
\caption{Eigenvalue and variance of the components (Comp.)}
\label{tab:}
\setlength{\tabcolsep}{0 pt}
\begin{threeparttable}
\begin{tabular*}{1.0\textwidth}{@{\extracolsep{\fill}}l*{14}{S[table-format=2.2]}} %<--- main changes
\toprule
Components & \textit{C 1} & \textit{C 2} & \textit{C 3} & \textit{C 4} & \textit{C 5}
& \textit{C 6} & \textit{C 7} & \textit{C 8} & \textit{C 9} &\textit{C 10} &\textit{C 11} &\textit{C 12} &\textit{C 13} &\textit{C 14} \\
\midrule
\multicolumn{15}{l}{\textit{Eigenvalue}} \\
PCA 1 & 4.76\tnote{*}& 1.82\tnote{*}& 1.56\tnote{*}& 1.03\tnote{*}& 0.92
& 0.88 & 0.88 & 0.74 & 0.49 & 0.29
& 0.25 & 0.22 & 0.17 & 0.06 \\
PCA 2 & 3.34\tnote{*}& 1.72\tnote{*}& 1.54\tnote{*}& 1.02\tnote{*}& 0.91
& 0.87 & 0.8 & 0.69 & 0.45 & 0.27
& 0.25 & 0.13 & & \\
\multicolumn{15}{l}{\textit{Percentage of variance}} \\
PCA 1 & 34 & 13 & 11.2 & 7.3 & 6.6
& 6.3 & 5.73 & 5.3 & 3.5 & 2.1
& 1.8 & 1.6 & 1.2 & 0.06 \\
PCA 2 & 27.9 & 14.4 & 12.8 & 8.5 & 7.6
& 7.3 & 6.7 & 5.8 & 3.7 & 2.3
& 2 & 1.1 & & \\
\bottomrule
\end{tabular*}
\begin{tablenotes}[para, flushleft]
\note The "*" indicate a value which can be considerate as significant.
\end{tablenotes}
\end{threeparttable}
\end{table*}
\end{document}
(在序言中我删除了所有未使用的包)