如何将表格单元格拆分为多列?

如何将表格单元格拆分为多列?

我试图实现下图所示的表格,但无法成功。我尝试了以下代码。

在此处输入图片描述

\begin{table}[]
\centering
\begin{tabular}{lllllll}
Dataset & Model & Evaluation criteria & Rank &  &  &  \\
 &  & RMSE & MAPE & MAE & R &  \\
(A) & Proposed &  &  &  &  &  \\
 & FN &  &  &  &  &  \\
 & NN &  &  &  &  &  \\
 & RX &  &  &  &  &  \\
(B) & Proposed &  &  &  &  &  \\
 & FN &  &  &  &  &  \\
 & NN &  &  &  &  &  \\
 & RX &  &  &  &  &  \\
(C) & Proposed &  &  &  &  &  \\
 & FN &  &  &  &  &  \\
 & NN &  &  &  &  &  \\
 & ARX &  &  &  &  &  \\
(D) & Proposed &  &  &  &  &  \\
 & FFN &  &  &  &  &  \\
 & LNN &  &  &  &  &  \\
 & ARX &  &  &  &  & 
\end{tabular}
\end{table}

答案1

为此,您必须加载multirow和。该包也很有用,因为它允许在标准单元格中使用换行符和常见格式。此外,您可以使用该命令为单元格定义一些垂直填充。rotatingmakecell\setcellgapes

\documentclass[10pt]{article}
\usepackage{array, rotating}
\usepackage{multirow, makecell}
\usepackage[a4paper, total={8in, 10in}]{geometry}

\begin{document}

\begin{table}[]
\centering\sffamily
\renewcommand{\theadfont}{\normalsize\bfseries}
\setcellgapes{1ex}\makegapedcells
\begin{tabular}{*{6}{c|}c}
\hline
\multirowthead{2}{Dataset} & \multirowthead{2}{Model} & \multicolumn{4}{c|}{\bfseries Evaluation criteria} & \multirowthead{2}{Rank} \\
\cline{3-6}
 & & \textbf{RMSE} & \textbf{MAPE} & \textbf{MAE} & \textbf{R} & \\
 \hline
\multirow{6}{*}{\turnbox{90}{(A)}} & Proposed & & & & & \\
 \cline{2-7}
 & FN & & & & & \\
 \cline{2-7}
 & NN & & & & & \\
 \cline{2-7}
 & RX & & & & & \\
 \hline
\multirow{6}{*}{\turnbox{90}{(B)}} & Proposed & & & & & \\
 \cline{2-7}
 & FN & & & & & \\
 \cline{2-7}
 & NN & & & & & \\
 \cline{2-7}
 & RX & & & & & \\
 \hline
\multirow{6}{*}{\turnbox{90}{(C)}} & Proposed & & & & & \\
 \cline{2-7}
 & FN & & & & & \\
 \cline{2-7}
 & NN & & & & & \\
 \cline{2-7}
 & ARX & & & & & \\
 \hline
\multirow{6}{*}{\turnbox{90}{(D)}} & Proposed & & & & & \\
 \cline{2-7}
 & FFN & & & & & \\
 \cline{2-7}
 & LNN & & & & & \\
 \cline{2-7}
 & ARX & & & & & \\
 \hline
\end{tabular}
\end{table}

\end{document} 

在此处输入图片描述

答案2

在此处输入图片描述

\begin{table}[]
\centering
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
\multirow{2}{*}{Dataset} & \multirow{2}{*}{Model} & \multicolumn{4}{c|}{Evaluation criteria}   &  \multirow{2}{*}{Rank} \\ 
\cline{3-6}
 &  & RMSE & MAPE & MAE & R &  \\
 \hline
\multirow{4}{*}{\rotatebox{90}{(A)}} & Proposed &  &  &  &  &  \\
\cline{2-7}
 & FN &  &  &  &  &  \\
 \cline{2-7}
 & NN &  &  &  &  &  \\
 \cline{2-7}
 & RX &  &  &  &  &  \\
 \cline{1-7}
\multirow{4}{*}{\rotatebox{90}{(B)}} & Proposed &  &  &  &  &  \\
\cline{2-7}
 & FN &  &  &  &  &  \\
 \cline{2-7}
 & NN &  &  &  &  &  \\
 \cline{2-7}
 & RX &  &  &  &  &  \\
 \cline{1-7}
\multirow{4}{*}{\rotatebox{90}{(C)}} & Proposed &  &  &  &  &  \\
\cline{2-7}
 & FN &  &  &  &  &  \\
 \cline{2-7}
 & NN &  &  &  &  &  \\
 \cline{2-7}
 & ARX &  &  &  &  &  \\
 \cline{1-7}
\multirow{4}{*}{\rotatebox{90}{(D)}} & Proposed &  &  &  &  &  \\
\cline{2-7}
 & FFN &  &  &  &  &  \\
 \cline{2-7}
 & LNN &  &  &  &  &  \\
 \cline{2-7}
 & ARX &  &  &  &  &\\
\hline
\end{tabular}
\end{table}

相关内容