5

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.

  • 2
    Welcome to TeX.SE. You can use \\ && A&B instead of \\ A&B. The first two && are to skip over the first two columns. You should also have a look at the booktabs package. – Peter Grill Jan 28 '14 at 18:53
  • It worked thanks!. You can move it as an answer. – Sathish Sanjeevi Jan 28 '14 at 18:56
5

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}
  • Is it possible to draw a line, only under "Implemented in". I tried \hline. It underlines the whole row. – Sathish Sanjeevi Jan 28 '14 at 18:59
  • Also, is it possible to align "First" and "Characteristics" equally spaced between the top and bottom lines? – Sathish Sanjeevi Jan 28 '14 at 19:00
  • You can use \cline{n-m} where n and m are the first and last columns under which you want the line. – Alan Munn Jan 28 '14 at 19:19
  • @Sathish Krishnan: load the multirow package and replace \multicolumn{1}{|c|}{\bfseries First} with \multirow{2}{*}{\bfseries First}. Same for "Characteristics". Also replace \multicolumn{2}{|c|}{\bfseries Implemented in} with \multicolumn{2}{c|}{\bfseries Implemented in} – Bernard Jan 28 '14 at 19:35
  • @Bernard: Thanks. Have incorporated your suggestions in the answer. – Peter Grill Jan 28 '14 at 21:30

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.