10

I have a table with two columns. In the first column there is no multiple column. But there are 11 multiple columns in the second column. The format looks like:

 | A |                     B                       |
 | _ | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |

A and B are headings, and 1, 2, 3, ..., 11 are subheadings of the table. After that there are some rows containing data.

I have tried several ways but cannot do it.

migrated from stackoverflow.com Sep 17 '11 at 19:16

This question came from our site for professional and enthusiast programmers.

15

What you need is the \multicolumn macro:

\documentclass{article}
\begin{document}
\begin{tabular}{|l|*{11}{c|}}
  \hline
   A & \multicolumn{11}{|c|}{B} \\ \hline
   \_ & 1&2&3&4&5&6&7&8&9&10&11 \\ \hline
\end{tabular}
\end{document}

output

  • 4
    Indeed, the key point here being that LaTeX looks at the question the 'other way around': you combine several columns into one. An alternative, for complex layouts, is to nest tabulars. – Joseph Wright Sep 17 '11 at 19:25
  • I replaced the bulky tabular column definition with a more elegant way, hope that's ok. – doncherry Oct 24 '12 at 20:55
0

Check out this page for easy table creation in Latex. https://www.tablesgenerator.com/

Create your table using GUI on the site and automatically generate Latex code for the table you created.

This site saved a lot of my time! And headache to create table in latex.

Your Answer

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