# table with two multicolumns

can someone help me fix this table?:

\documentclass{article}
\usepackage{siunitx,booktabs,caption}

\newcommand{\splitcell}[1]{%
\begin{tabular}{@{}c@{}}\strut#1\strut\end{tabular}%
}

\begin{document}

\begin{table}[htp]
\centering

\caption{The table caption}

\begin{tabular}{
S[table-format=2.0]
S[table-format=1.0]
S[table-format=1.6]
S[table-format=1.4]
S[table-format=1.3]
}

\toprule
{$t$ (\si{\nano\meter})} &
{$W$ (\si{\micro\meter})} &
\multicolumn{3}{c}{My results} \\
\cmidrule{3-5}
& &
{Re} &
{\splitcell{Theor.\\Overlap\\factor}} &
{\splitcell{Theor.\\MPA\\(\si{dB/mm})}} \\
\midrule
25 & 8 & 1.447413 & 0.9627 & 2.128 \\
& 4 & 1.446128 & 0.9538 & 1.20  \\
\midrule
31 & 8 & 1.448499 & 0.9377 & 4.196 \\
& 4 & 1.446889 & 0.9571 & 2.78  \\
\bottomrule

\multicolumn{3}{c}{Her results} \\
\cmidrule{6-8}
& &
{Re} &
{\splitcell{Theor.\\Overlap\\factor}} &
{\splitcell{Theor.\\MPA\\(\si{dB/mm})}} \\
\midrule
25 & 8 & 1.447413 & 0.9627 & 2.128 \\
& 4 & 1.446128 & 0.9538 & 1.20  \\
\midrule
31 & 8 & 1.448499 & 0.9377 & 4.196 \\
& 4 & 1.446889 & 0.9571 & 2.78  \\
\bottomrule

\end{tabular}

\end{table}
\end{document}

-
What’s the problem? You didn't explain it. –  Aradnix Aug 14 at 16:40
the forth column (her results) has a problem. I got help in doing the table up to the (my results) column but when I insert one extra muticolumn , I get an error. Please, try the MWE and you will know. –  Naema Aug 14 at 16:43
here is my first question:tex.stackexchange.com/questions/196243/… –  Naema Aug 14 at 16:44
Is the same table from your first question? Running your MWE of this question, in the line 42 instead of \midrule you wrote \cmidrule, that's the error. Please try to read the information of the bugs when you compile your documents, there is very useful information. –  Aradnix Aug 14 at 17:12
I see the problem is not because the \cmidrule command in fact, but it was because the definition was wrong. In the line 20 you create a rule between the columns 3 and 5 and was right. Bun in the line 42 you try to create another rule between the columns 6 and 8 in a table of 5 columns, that's the mistake. Also the row Her results is misaligned, you need to add in the line 33 a couple of ampersands (&) before the \multicolumn{3}{c}{Her results}. –  Aradnix Aug 14 at 17:24

(migrated the following answer from a posting by the same OP, see organizing a table, that was later deemed to be a duplicate)

Here's a solution that uses the tabularx package and a modified form of that package's X column type to typeset the six multiline header cells in the second row of the header. A happy side effect of using tabularx in this way is that there's no need to use the \splitcell macro.

\documentclass{article}
\usepackage{siunitx,booktabs,tabularx,ragged2e}
\sisetup{group-digits=false} % optional
\newcolumntype{C}{>{\Centering\arraybackslash}X}
\newcommand\mC[1]{\multicolumn{1}{@{}C@{}}{#1}} % handy shortcut macro

\begin{document}
\begin{table}
\caption{The table caption}\label{tab:mine-and-hers}

\begin{tabularx}{\textwidth}{%
@{} cc *{2}{S[table-format=1.6]
S[table-format=1.4]
S[table-format=1.3]} @{} }
\toprule
$t$ (\si{\nano\meter}) & $W$ (\si{\micro\meter}) &
\multicolumn{3}{c}{My results} & \multicolumn{3}{c}{Her results} \\
\cmidrule(lr){3-5} \cmidrule(l){6-8}
& &
\mC{Re} & \mC{Theor.\ Overlap factor} & \mC{Theor.\ MPA (\si{dB/mm})} &
\mC{Re} & \mC{Theor.\ Overlap factor} & \mC{Theor.\ MPA (\si{dB/mm})}\\
\midrule
25 & 8 & 1.447413 & 0.9627 & 2.128 & 1.447413 & 0.9627 & 2.128\\
& 4 & 1.446128 & 0.9538 & 1.20  & 1.446128 & 0.9538 & 1.20\\
\midrule
31 & 8 & 1.448499 & 0.9377 & 4.196 & 1.448499 & 0.9377 & 4.196\\
& 4 & 1.446889 & 0.9571 & 2.78  & 1.446889 & 0.9571 & 2.78\\
\bottomrule
\end{tabularx}
\end{table}
\end{document}

-
thanks Mico, it works but I do not know why the table appears in the second page!. Something is blocking the table from being in page one using this code. –  Naema Aug 14 at 23:20
oh, that is right. I added [htp] just after \begin{table} and my table appears in page 1 now. thanks Mico!. –  Naema Aug 15 at 4:33
@Naema - Glad it's working for you. –  Mico Aug 15 at 4:43
# Mico,I want to chat with you if possible, I have a different table to organize and I have a deadline . since I am new to do tables in Latex, I still need more guidance. I do not want to post another table question, may you assist me on it #Mico? –  Naema Aug 15 at 4:47
@Naema - Actually, am getting ready to go to work at the moment, can't spend much time online. :-( If your new issue is with a different table, please do post a new query. There are plenty of people on this site who are good at doing LaTeX tables. –  Mico Aug 15 at 4:50

Well I don't understand exactly what you what to do with the table, or if you are understanding well how to build a table in LaTeX.

According to what I understood from your table, and from your MWE, I would write it in this way

\documentclass{article}
\usepackage{siunitx,booktabs,caption}

\newcommand{\splitcell}[1]{%
\begin{tabular}{@{}c@{}}\strut#1\strut\end{tabular}%
}

\begin{document}

\begin{table}[htp]
\centering

\caption{The table caption}

\begin{tabular}{S[table-format=2.0] S[table-format=1.0] S[table-format=1.6] S[table-format=1.4] S[table-format=1.3]}

\toprule
{$t$ (\si{\nano\meter})} & {$W$ (\si{\micro\meter})} & \multicolumn{3}{c}{My results} \\
\cmidrule{3-5}
&                           & {Re}     & {\splitcell{Theor.\\Overlap\\factor}} & {\splitcell{Theor.\\MPA\\(\si{dB/mm})}} \\
\midrule
25                       & 8                         & 1.447413 & 0.9627                                & 2.128 \\
& 4                         & 1.446128 & 0.9538                                & 1.20  \\
\midrule
31                       & 8                         & 1.448499 & 0.9377                                & 4.196 \\
& 4                         & 1.446889 & 0.9571                                & 2.78  \\
\bottomrule
&                           & \multicolumn{3}{c}{Her results} \\
\cmidrule{3-5} % 6-8
&                           & {Re}                                             & {\splitcell{Theor.\\Overlap\\factor}} & {\splitcell{Theor.\\MPA\\(\si{dB/mm})}} \\
\midrule
25                       & 8                         & 1.447413  & 0.9627                               & 2.128 \\
& 4                         & 1.446128  & 0.9538                               & 1.20  \\
\midrule
31                       & 8                         & 1.448499  & 0.9377                               & 4.196 \\
& 4                         & 1.446889  & 0.9571                               & 2.78  \\
\bottomrule
\end{tabular}
\end{table}
\end{document}


Notice that I widened the rows for align them and in this way make easier to see how the table was build. So as you can see, the table is right with just 5 columns. If you need more, then you must to add them in the same line where you define the tabular environment. But don't confuse the rows with the columns.

## Update

Finally you asked if it's possible to get the results of her near to yours instead of beneath them?

Sure it's possible, but it depends not of LaTeXbut you to define correctly the table. The example you showed has 5 columns, if you need the results to be contiguous to yours, then you must change the dimensions of the table from the beginning.

Something like this:

\documentclass{article}
\usepackage{siunitx,booktabs,caption}

\newcommand{\splitcell}[1]{%
\begin{tabular}{@{}c@{}}\strut#1\strut\end{tabular}%
}

\begin{document}

\begin{table}[htp]
\centering

\caption{The table caption}

\begin{tabular}{
S[table-format=2.0] % Column 1
S[table-format=1.0] % Column 2
S[table-format=1.6] % Column 3
S[table-format=1.4] % Column 4
S[table-format=1.3] % Column 5
S[table-format=1.6] % Column 6 same width than 3
S[table-format=1.4] % Column 7 same width than 4
S[table-format=1.3] % Column 8 same width than 5
}

\toprule
{$t$ (\si{\nano\meter})} & {$W$ (\si{\micro\meter})} & \multicolumn{3}{c}{My results} & \multicolumn{3}{c}{Her results} \\
\cmidrule{3-5} \cmidrule{6-8}
& & {Re} & {\splitcell{Theor.\\Overlap\\factor}} & {\splitcell{Theor.\\MPA\\(\si{dB/mm})}} & {Re} & {\splitcell{Theor.\\Overlap\\factor}} & {\splitcell{Theor.\\MPA\\(\si{dB/mm})}}\\
\midrule
25 & 8 & 1.447413 & 0.9627  & 2.128 & 1.447413  & 0.9627 & 2.128\\
& 4 & 1.446128 & 0.9538  & 1.20  & 1.446128  & 0.9538 & 1.20\\
\midrule
31 & 8 & 1.448499 & 0.9377  & 4.196 & 1.448499  & 0.9377 & 4.196\\
& 4 & 1.446889 & 0.9571  & 2.78  & 1.446889  & 0.9571 & 2.78\\
\bottomrule
\end{tabular}
\end{table}
\end{document}


You need to add in the line \begin{tabular}{... the last 3 columns for get the same width of column, this is: S[table-format=1.6] S[table-format=1.4] S[table-format=1.3].

The second part of the trick is to fill the rows with the content of those three columns.

In the line 29 you can add now \cmidrule{6-8} without errors.

In your MWE the data in the columns 6 and 8 are the same and if this is true would be redundant since you only need to add (I think) the column of her results. In that case the table is narrower and less complex.

-
thanks Aradnix, I got the table I want now except that I wanted the column (her results) to be next to the column (my results) not beneath it!!!! Is this possible? –  Naema Aug 14 at 20:33
Yes it is possible. I edited the answer. Read it carefully and I hope you understand better how to do it. If isn't clear yet, comment again. –  Aradnix Aug 14 at 21:16
Please do not duplicate your question with different names. Try to explain you better once and be patient. I took the time to decipher what was your question (implied), please value the time and effort that people on this site dedicated to answer questions. –  Aradnix Aug 14 at 21:29
In the end of line 22 add a pipe | and that would add a vertical line between both results. Please try to read more about tables and floating objects in LaTeX. There is a lot of tutorials, manuals and books in the web. –  Aradnix Aug 14 at 21:37
(+1) for sheer patience ;). –  cfr Aug 14 at 21:42