我正在使用以下代码:
\definecolor{atlas}{RGB}{11,128,195}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\begin{table}[H]
\centering
\begin{tabular}{| l | C{2cm} | C{4cm} | C{5cm} |}
\hline
\rowcolor{atlas} \multicolumn{1}{|c|}{\textbf{CANbus}} & \textbf{Port} & \textbf{Computer} & \textbf{Project} \\
\hline
\hline
EI\textunderscore A\textunderscore top & can1 & PC4 & PROJ4 \\
\cline{1-2}
EI\textunderscore A\textunderscore bottom & can0 & \\
\hline
EI\textunderscore C\textunderscore top & can0 & PC5 & PROJ5 \\
\cline{1-2}
EI\textunderscore C\textunderscore bottom & can1 & \\
\hline
\end{tabular}
\caption{All communication parts of the CANbuses.}
\end{table}
如您所见,计算机和项目行未垂直居中,而且合并单元格的右边框缺少一半的长度。您知道我做错了什么吗?
提前致谢。
答案1
可以用 来完成multirow
,并填写空单元格的数量;
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{multirow}
\usepackage{float}
\definecolor{atlas}{RGB}{11,128,195}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\begin{document}
\begin{table}[H]
\centering
\begin{tabular}{| l | C{2cm} | C{4cm} | C{5cm} |}
\hline
\rowcolor{atlas} \multicolumn{1}{|c|}{\textbf{CANbus}} & \textbf{Port} & \textbf{Computer} & \textbf{Project} \\
\hline
\hline
EI\textunderscore A\textunderscore top & can1 & \multirow{2}{=}{\centering PC4} & \multirow{2}{=}{\centering PROJ4} \\
\cline{1-2}
EI\textunderscore A\textunderscore bottom & can0 & & \\
\hline
EI\textunderscore C\textunderscore top & can0 & \multirow{2}{=}{\centering PC5} & \multirow{2}{=}{\centering PROJ5} \\
\cline{1-2}
EI\textunderscore C\textunderscore bottom & can1 & & \\
\hline
\end{tabular}
\caption{All communication parts of the CANbuses.}
\end{table}
\end{document}