如何使表格的某些单元格包含多行?

如何使表格的某些单元格包含多行?

我正在尝试制作类似附图中的表格

在此处输入图片描述

我在用:

\begin{table} 

\small

    \begin{tabular}{|p{1.1cm}|p{2.3cm}|p{2cm}|p{3.2cm}|p{1.5cm}| p{1.1cm}|}

\end {table}

但未能成功,因为有些单元格需要分成多行。有人能帮忙吗?不胜感激

答案1

这就是你想要的效果吗?——

\documentclass{article}

\begin{document}

\begin{table} \small%
\begin{tabular}{|p{1.1cm}|p{2.3cm}|p{2cm}|p{3.2cm}|p{1.5cm}| p{1.1cm}|}
\hline
Group & Strategies & Data & Evaluated \\
\hline
Baseline & First strategy & Data 1 & Yes \\
\cline{2-2} \cline{4-4}
                 & Second strategy & Data 2 & No \\
\hline
Solution & First solution & Data 1 & Yes \\
                 &                & Data 2 &  \\
\cline{2-4}
                 & Second solution & Data 1 & Yes \\
                 &                & Data 2 &  \\
                 &                & Data 3 &  \\
\cline{2-4}
                 & Third solution & Data 1 & No \\
                 &                & Data 2 &  \\
                 &                & Data 3 &  \\
\hline
\end{tabular}
\end{table}

\end{document}

最有可能生成如下所示的表格......

在此处输入图片描述

答案2

我建议使用以下三种布局之一,基于tabularxbooktabs(用于带有一些填充的水平规则)和\makecell(允许在标准单元格中换行)。在我看来,更专业的外观是只有几条不同粗细的水平线:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tabularx, makecell, booktabs}
\renewcommand{\cellalign}{lc}
\renewcommand{\theadalign}{lc}
\renewcommand{\theadfont}{\normalsize\bfseries}
\newcommand\nl{\newline}

\begin{document}

\begin{table}[!htb]
\small\sffamily\centering%
\setlength{\extrarowheight}{2pt}
\begin{tabularx}{\linewidth}{|l|*{2}{X|}c|}
\hline
Group & Strategies & Data & Evaluated \\
\hline
Baseline & First strategy & Data 1 & Yes \\
\cline{2-2} \cline{4-4}
                 & Second strategy & Data 2 & No \\
\hline
Solution & First solution & Data 1\nl Data 2 & Yes \\
\cline{2-4}
                 & Second solution & Data 1\nl Data 2\nl Data 3 & Yes \\
\cline{2-4}
                 & Third solution & Data 1\nl Data 2\nl Data 3 & No \\
\hline
\end{tabularx}
\end{table}

\begin{table}[!htb]
\small\sffamily\centering%
\begin{tabularx}{\linewidth}{l*{2}{X}c}
\toprule
\thead{Group} & \thead{Strategies} & \thead{Data} & \thead{Evaluated} \\
\midrule
Baseline & First strategy & Data 1 & Yes \\
                 & Second strategy & Data 2 & No \\
\cmidrule(lr){1-4}
Solution & First solution & Data 1\nl Data 2 & Yes \\
\addlinespace
                 & Second solution & Data 1\nl Data 2\nl Data 3 & Yes \\
\addlinespace
                 & Third solution & Data 1\nl Data 2\nl Data 3 & No \\
\bottomrule
\end{tabularx}
\end{table}

\begin{table}[!htb]
\small\sffamily\centering%
\setlength{\extrarowheight}{2pt}
\begin{tabular}{|*{4}{l|}}
\hline
Group & Strategies & Data & Evaluated \\
\hline
Baseline & First strategy & Data 1 & Yes \\
\cline{2-2} \cline{4-4}
                 & Second strategy & Data 2 & No \\
\hline
Solution & First solution & \makecell{Data 1\\ Data 2 } & Yes \\
\cline{2-4}
                 & Second solution & \makecell{Data 1 \\ Data 2 \\ Data 3} & Yes \\
\cline{2-4}
                 & Third solution & \makecell{Data 1 \\ Data 2 \\ Data 3} & No \\%
\hline
\end{tabular}
\end{table}

\end{document} 

在此处输入图片描述

相关内容