[Tex/LaTex] Table heading multicolumn problem

multicolumntables

I have the following code, which needs 2 sub-columns in the last main column. I have written code as follows:

\begin{table}
  \centering
    \begin{tabular}{|c|l|c|c|}
    \hline
    \multicolumn{1}{|c|}{\bfseries First} & \multicolumn{1}{|c|}{\bfseries Characteristics} & \multicolumn{2}{|c|}{\bfseries Implemented in}\\ A&B \\ \hline
    a & b & c & d \\
    1 & 2 & 3 & 4\\
    \end{tabular}
\end{table}

The result is

enter image description here

I want the "A" and "B" as sub-column within the "Implemented in" column.

Best Answer

You can use \\ && A&B instead of \\ A&B. The first two && are to skip over the first two columns.

enter image description here

Notes:

  • As per Bernard'scmment, the multirow package was used to vertically center the first two headers across the two rows.
  • As per @AlanMunn's comment, \cline{3-4} can be used to draw lines across specified columns.

However, I would strongly recommend you have a look at the booktabs package for tables:

enter image description here

Code:

\documentclass{article}
\usepackage{multirow}

\begin{document}
\begin{tabular}{|c|l|c|c|}
    \hline
    \multirow{2}{*}{\bfseries First} & 
    \multirow{2}{*}{\bfseries Characteristics} & 
    \multicolumn{2}{|c|}{\bfseries Implemented in}\\ \cline{3-4}
    && A&B \\ \hline
    %------
    & b & c & d \\
    1 & 2 & 3 & 4\\
\end{tabular}
\end{document}

Code: booktabs

\documentclass{article}
\usepackage{booktabs}
\usepackage{multirow}

\begin{document}
\begin{tabular}{c l c c}
    \toprule
    \multirow{2}{*}{\bfseries First} & 
    \multirow{2}{*}{\bfseries Characteristics} & 
    \multicolumn{2}{c}{\bfseries Implemented in}\\ \cmidrule(lr){3-4}
    && A&B \\ \cmidrule(lr){1-4}
    %------
    & b & c & d \\
    1 & 2 & 3 & 4\\
    \bottomrule
\end{tabular}
\end{document}
Related Question