7

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
  • 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. Jan 28, 2014 at 18:53
  • It worked thanks!. You can move it as an answer.
    – SKPS
    Jan 28, 2014 at 18:56

2 Answers 2

8

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}
6
  • Is it possible to draw a line, only under "Implemented in". I tried \hline. It underlines the whole row.
    – SKPS
    Jan 28, 2014 at 18:59
  • Also, is it possible to align "First" and "Characteristics" equally spaced between the top and bottom lines?
    – SKPS
    Jan 28, 2014 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, 2014 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, 2014 at 19:35
  • @Bernard: Thanks. Have incorporated your suggestions in the answer. Jan 28, 2014 at 21:30
3

With the new package tabularray is simple. Using it you need to insert one ampersand for each column, i.e. in your case three ampersands per row:

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}
\begin{table}[ht]
     \centering
\begin{tblr}{vlines,
             colspec={c l Q[c,wd=3.3em] Q[c,wd=3.3em]},
             row{1}={font=\bfseries},
             }
    \toprule
\SetCell[r=2]{c} First   
    &   \SetCell[r=2]{c} Characteristics 
        &  \SetCell[c=2]{c} Implemented in 
            &       \\
    \midrule
    &   & A & B     \\ 
    \midrule
    & b & c & d     \\
 1  & 2 & 3 & 4     \\
    \bottomrule
    \end{tblr}
\end{table}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .