LaTeX 中的宏多列和行

LaTeX 中的宏多列和行

我有一个这样的表格,但在使用 LaTeX 时,\multicolumn输出\multirow视图并不完美,单元格之间似乎有一些重叠,当我们使用这些命令时,单元格之间没有任何分隔符。你能帮我把这个表格做得更好吗?

\begin{table}[h]
\centering
    \begin{tabular}{ | p{1.2cm} | p{1.6cm} | p{1.6cm} | p{1.6cm} | p{1.6cm} |}
    \hline
    \multirow{2}{*}{Scenario} & \multicolumn{2}{|c|}{Urban} & \multicolumn{2}{|c|}{Highway} \\
     & Without RSU & With RSU & Without RSU & With RSU \\ \hline
    PDR & e-HBCWC & HBCWC & e-HBCWC & \\ \hline
    End-to-End Delay & e-HBCWC & DCF & HBCWC & \\ \hline
    Overall & e-HBCWC & e-HBCWC & e-HBCWC & \\ \hline
    \end{tabular}
\end{table}

答案1

我仍然看到一个表的使用情况\multirow不能通过删除它来改善。

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{table}[htp]
\centering
\addtolength{\tabcolsep}{-2pt} % adjust to fit
\begin{tabular}{lllll}
\toprule
 & \multicolumn{2}{c}{Urban} & \multicolumn{2}{c}{Highway} \\
\cmidrule(lr){2-3}\cmidrule(lr){4-5}
Scenario         & Without RSU & With RSU & Without RSU & With RSU \\
\midrule
PDR              & e-HBCWC     & HBCWC    & e-HBCWC     & \\
End-to-End Delay & e-HBCWC     & DCF      & HBCWC       & \\
Overall          & e-HBCWC     & e-HBCWC  & e-HBCWC     & \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

在此处输入图片描述

如果你真的想使用\multirow并划线表格(这是邪恶的),请尝试

\documentclass{article}
\usepackage{multirow}
\newlength{\without}
\newcommand{\adjustsize}[1]{\makebox[\without]{#1}}
\begin{document}

\begin{table}[!htb]
\settowidth{\without}{Without RSU}
\addtolength{\tabcolsep}{-2pt} % adjust to fit
\begin{tabular}{ | *{5}{l|} }
\hline
\multirow{2}{*}{Scenario} & \multicolumn{2}{c|}{Urban} & \multicolumn{2}{c|}{Highway} \\
& Without RSU & \adjustsize{With RSU} & Without RSU & \adjustsize{With RSU} \\ \hline
    PDR & e-HBCWC & HBCWC & e-HBCWC & \\ \hline
    \begin{tabular}{@{}l@{}}End-to-End\\ Delay\end{tabular}
      & e-HBCWC & DCF & HBCWC & \\ \hline
    Overall & e-HBCWC & e-HBCWC & e-HBCWC & \\ \hline
\end{tabular}
\end{table}

\end{document}

在此处输入图片描述

所做的调整\tabcolsep是为了使表格适合。您可能需要它,也可能需要它,这取决于文档的文本宽度。

相关内容