1

I am using the code:

\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}

Which gives the output: enter image description here

As you can see, the Computer and Project rows are not centered vertically and moreover, the right border in the merged cells in missing half of its length. Any ideas what I am doing wrong?

Thanks in advance.

1 Answer 1

1

It can be done with multirow, and completing the number of empty cells ;

    \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} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.