答案1
我认为您正在寻找\multicolumn
:\multirow
\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{array}
\usepackage{multirow}
\newcolumntype{C}{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{2.3cm}}
% https://tex.stackexchange.com/a/12712/156344
\begin{document}
\setcounter{table}{11}
\begin{table}
\centering
\caption{Some caption}
\begin{tabular}{|C|C|C|C|C|C|}
\hline
\multicolumn{3}{|c|}{Long long long long long long long long text} & \multicolumn{3}{c|}{Long long long long long long long long text}\\
\hline
Text & Primary Code & Text & Text & Text & Text\\
\hline
Text & Text & \multirow[t]{2}{*}{Some text} & Text & Text & \multirow[t]{2}{*}{Some text}\\ \cline{1-2} \cline{4-5}
Text & Text & & Text & Text & \\
\hline
\end{tabular}
\end{table}
\end{document}
额外的水平线会弄乱你的表格,所以我把它删掉了,请不要使用它。
以下是推荐的版本,删除了所有垂直线,并对水平线的粗细进行了一些更改(借助booktabs
):
\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{array}
\usepackage{multirow}
\usepackage{booktabs}
\newcolumntype{C}{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{2.3cm}}
\begin{document}
\setcounter{table}{11}
\begin{table}
\centering
\caption{Some caption}
\begin{tabular}{CCCCCC}
\toprule
\multicolumn{3}{c}{Long long long long long long long long text} & \multicolumn{3}{c}{Long long long long long long long long text}\\
\midrule
Text & Primary Code & Text & Text & Text & Text\\
%\midrule
\cmidrule(r){1-3} \cmidrule(l){4-6} % For better column separation, thanks to Mico!
Text & Text & \multirow[t]{2}{*}{Some text} & Text & Text & \multirow[t]{2}{*}{Some text}\\
Text & Text & & Text & Text & \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
我建议您使用一个tabularx
环境,将总宽度设置为\textwidth
,并设置 6 个等宽列。我还建议您省略所有垂直线,使用较少但间距适当的水平线(使用包的宏booktabs
),以使表格看起来更开放。
\documentclass{article} % select a suitable document class
\usepackage[a4paper,margin=2.5cm]{geometry} % set suitable page parameters
\usepackage[skip=0.333\baselineskip]{caption} % optional
\usepackage{tabularx,booktabs,ragged2e,amsmath}
\newcolumntype{C}{>{\Centering\arraybackslash}X}
\DeclareMathOperator{\ED}{ED}
\newcommand\ris{\mathrm{ris}}
\newcommand\rs{\mathrm{rs}}
\begin{document}
\begin{table}
\setlength\tabcolsep{3pt} % default: 6pt
\caption{Example comparison of \dots\ between previous and our approaches}
\begin{tabularx}{\textwidth}{@{} *{6}{C} @{}}
\toprule
\multicolumn{3}{@{}c}{`\dots' coded `ri' (Previous Approach)} &
\multicolumn{3}{c@{}}{`\dots' coded `r' (Our Approach)} \\
\cmidrule(r){1-3} \cmidrule(l){4-6}
Word & Primary Word & Edit Distance & Word & Primary Word & Edit Distance \\
\midrule
\dots\ (correct) & Ris & $\ED(\ris\mid \rs)=1$ & & & \\ \addlinespace
\dots\ (incorrect) & Rs & & & & \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
答案3
这里是一种用 构建该表的方法{NiceTabular}
(nicematrix
但是,和许多人一样,我建议采用 的精神进行设计booktabs
)。
\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{nicematrix}
\usepackage{caption}
\begin{document}
\setcounter{table}{11}
\begin{table}
\centering
\caption{Some caption}
\begin{NiceTabular}{*{6}{m[c]{2.3cm}}}[hvlines]
\Block{1-3}{Long long long long long long long long text} &&&
\Block{1-3}{Long long long long long long long long text} \\
Text & Primary Code & Text & Text & Text & Text\\
Text & Text & \Block{2-1}{} Some text & Text & Text & \Block{2-1}{} Some text \\
Text & Text & & Text & Text & \\
\end{NiceTabular}
\end{table}
\end{document}