我有这个MWE:
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{table}[here]
\begin{center}
\begin{tabular}{|l|l|c|}
\hline
\multicolumn{2}{|c|}{\textbf{SED}} & \multirow{2}{*}{\textbf{\% compressione}} \\
\cline{1-2}
\textbf{MC} & \textbf{DP} & \\
\hline
\hline
0.00016032 & 0.0001750267 & 10\%\\
\hline
\end{tabular}
\end{center}
\end{table}
\end{document}
它实现了这个图像:
前两列在左侧的格式正确,但我希望 MC 和 DP 居中,我该怎么做?
答案1
就像你用“SED”做的那样\multicolumn
:
\multicolumn{1}{|c|}{\textbf{MC}}
答案2
该makecell
包在这里很方便,因为它允许对序言中声明的所有列标题使用通用格式:\makecell
或\thead
命令的内容默认为垂直和水平居中。它还定义了用于不同厚度的 hlines 的命令。还可以考虑使用包booktabs
:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[x11names]{xcolor}
\usepackage{array, booktabs}
\usepackage{makecell}
\renewcommand{\theadfont}{\color{Tomato3}\bfseries}
\setcellgapes{3pt}
\begin{document}
{\makegapedcells
\begin{tabular}{!{\vrule width1pt}p{.5in}|p{1in}|p{1in}|p{1in}!{\vrule width1pt}}
\Xhline{1pt}
\thead{S. No.} & \thead{Book Name} & \thead{Author} &
\thead{Publisher}\\
\hline
a & b & c & d\\
\Xhline{1pt}
\end{tabular}}
\vskip 1cm
\begin{tabular}{p{.5in}*{3}{p{1in}}}
\toprule
\thead{S. No.} & \thead{Book Name} & \thead{Author} &
\thead{Publisher}\\
\cmidrule(l{5pt}r{5pt}){1-4}
a & b & c & d\\
\bottomrule
\end{tabular}
\end{document}