我已经使用过这个代码
\documentclass{article}
\usepackage{multirow}
\usepackage[margin=1cm]{geometry}
\begin{document}
\begin{table}
\centering
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
\multirow{2}{*}{Image} & \multirow{2}{*}{Actual Entropy} & \multirow{2}{*}{Encrypted Entropy} & \multicolumn{2}{|c|}{Correlation coefficient plain}& \multicolumn{2}{|c|}{Correlation coefficient encrypted}\\
\cline{4-5} \cline{6-7}
& & & XXXX & XXX & XXXX& xx \\
\hline
Barbara gray & xxx & xxx & xx & xx & xx& xxx\\
Bridge & yyy & y & yy & yy & yyy& xx\\
Goldhill & zzz & zz & zz & zzzz & zz& \\
Mountain & zzz & zz & zz & zzzz & zz& \\
zelda & zzz & zz & zz & zzzz & zz& \\
\hline
\end{tabular}
\end{table}
\end{document}
答案1
您可以手动指定多行单元格宽度(它们本质上是p
列)并将多列设置为p
,如下所示:
\documentclass{article}
\usepackage{multirow}
\usepackage[margin=1cm]{geometry}
\begin{document}
\begin{table}
\centering
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
\multirow{3}{*}{Image} & \multirow{3}{1.5cm}{\centering Actual Entropy} & \multirow{3}{2cm}{\centering Encrypted Entropy} & \multicolumn{2}{|p{2.5cm}|}{\centering Correlation coefficient plain}& \multicolumn{2}{|p{3.2cm}|}{\centering Correlation coefficient encrypted}\\
\cline{4-5} \cline{6-7}
& & & XXXX & XXX & XXXX& xx \\
\hline
Barbara gray & xxx & xxx & xx & xx & xx& xxx\\
Bridge & yyy & y & yy & yy & yyy& xx\\
Goldhill & zzz & zz & zz & zzzz & zz& \\
Mountain & zzz & zz & zz & zzzz & zz& \\
zelda & zzz & zz & zz & zzzz & zz& \\
\hline
\end{tabular}
\end{table}
\end{document}
因此得到一个与您发布的表格类似的表格。
我还必须将多行线从 更改为2
以3
适应表格的新高度。
附言:请原谅截图的质量,在你的机器上看起来会好得多
答案2
您可以使用makecell
包,它允许在标准单元格中换行,而无需指定宽度。我还有一个更专业的变体,没有任何垂直规则和不同宽度的水平规则booktabs
:
\documentclass{article}
\usepackage{multirow, makecell, booktabs}
\setcellgapes{4pt}
\usepackage[margin=1cm]{geometry}
\begin{document}
\begin{table}[!htb]
\centering\makegapedcells
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
\multirowcell{3}{Image} & \multirowcell{3}{Actual\\ Entropy} & \multirowcell{3}{Encrypted\\ Entropy} & \multicolumn{2}{c|}{\makecell{Correlation\\ coefficient plain}}& \multicolumn{2}{c|}{\makecell{Correlation\\ coefficient encrypted}}\\
\cline{4-5} \cline{6-7}
& & & XXXX & XXX & XXXX & xx \\
\hline
Barbara gray & xxx & xxx & xx & xx & xx & xxx \\
Bridge & yyy & y & yy & yy & yyy & xx \\
Goldhill & zzz & zz & zz & zzzz & zz & \\
Mountain & zzz & zz & zz & zzzz & zz & \\
zelda & zzz & zz & zz & zzzz & zz & \\
\hline
\end{tabular}
\end{table}
\vspace*{1cm}
\begin{table}[!htb]
\centering\setcellgapes{1pt}\makegapedcells
\begin{tabular}{*{7}{c}}
\toprule
\multirowcell{3}{Image} & \multirowcell{3}{Actual\\ Entropy} & \multirowcell{3}{Encrypted\\ Entropy} & \multicolumn{2}{c}{\makecell{Correlation\\ coefficient plain}}& \multicolumn{2}{c}{\makecell{Correlation\\ coefficient encrypted}}\\
\cmidrule(lr){4-5} \cmidrule(lr){6-7}
& & & XXXX & XXX & XXXX & xx \\
\midrule
Barbara gray & xxx & xxx & xx & xx & xx & xxx \\
Bridge & yyy & y & yy & yy & yyy & xx \\
Goldhill & zzz & zz & zz & zzzz & zz & \\
Mountain & zzz & zz & zz & zzzz & zz & \\
zelda & zzz & zz & zz & zzzz & zz & \\
\bottomrule
\end{tabular}
\end{table}
\end{document}