How to get two \ multicolum in LaTeX table?

I am trying to get something like this:

---------------------------------
|  Hello world  |     Again     |
---------------------------------
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
---------------------------------

So I wrote:

\begin{tabular}{l|l|l}
\multicolumn{4}{c}{Población total en millones}
\multicolumn{4}{c}{Porcentaje de población rural}\\
\hline
1975 & 2001 & 2003 & 2015 & 1975 & 2001 & 2003 & 2015\\
\hline
10,3 & 15,4 & 16 & 17,9 & 21,6 & 14 & 13 & 9,8
\end{tabular}

But this gives me this error:

! Invalid \ omit. \ multispan → \ omit \ @multispan

What can I do?

Edit

Also, how can I get the border between two columns?

Thank.

+3
source share
1 answer

First you need to set 8 columns, and then move to it. :) String columns should also be separated by the alignment operator &.

\begin{tabular}{l|l|l|l|l|l|l|l}
  \multicolumn{4}{c}{Poblaci\'{o}n total en millones} &
  \multicolumn{4}{c}{Porcentaje de poblaci\'{o}n rural}\\
  \hline
  1975 & 2001 & 2003 & 2015 & 1975 & 2001 & 2003 & 2015\\
  \hline
  10,3 & 15,4 & 16 & 17,9 & 21,6 & 14 & 13 & 9,8
\end{tabular}

To get a row between columns, just change the qualifier:

\begin{tabular}{l|l|l|l|l|l|l|l}
    \multicolumn{4}{c|}{Poblaci\'{o}n total en millones} &
    \multicolumn{4}{|c}{Porcentaje de poblaci\'{o}n rural}\\
    \hline
    1975 & 2001 & 2003 & 2015 & 1975 & 2001 & 2003 & 2015\\
    \hline
    10,3 & 15,4 & 16 & 17,9 & 21,6 & 14 & 13 & 9,8
\end{tabular}

More information on formatting the table is completed on WikiBooks. :)

+4
source

Source: https://habr.com/ru/post/1748459/


All Articles