3

I needed to do a table with 4 columns.The first has 2 cells. the second has 4 cells. The third is split into three different things. And, the fourth is split into 3 different things. I know how to do a table with four columns but do not know how to split a column. The pictures attached is exactly what I wanted to do. Note:The (her results) column is not shown in the picture attached but it should be identical to (my results) column.I do not know if my MWE would help or not. I could not know how![enter image description here][1] to do this table properly. Can anyone help? my MWE is:

\begin{table}[ht]
\caption{.} % title of Table
\centering % used for centering table
\begin{tabular}{c c c c} % centered columns (4 columns)
\hline\hline %inserts double horizontal lines
Metal thickness$(nm)$ & Metal width$(\mum)$ & My Results & Her Results\\ [0.5ex] % inserts table 
%heading
\hline % inserts single horizontal line
25 & 8 & 1.447413 & 0.9627 & 2.128 \\ % inserting body of the table

After this question was solved by #egreg, I tried to add an extra column that is also composed of three parts like the (my results) column . However, I had an error.this is what I thought to be the way of adding an extra column in the code provided in the answer by egreg.

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



\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}





  [1

]: https://i.stack.imgur.com/JmpZE.png

Naema
  • 2,305

1 Answers1

4

Here's my proposal, with booktabs, siunitx and no vertical rule:

\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
\end{tabular}

\end{table}

\end{document}

enter image description here

egreg
  • 1,121,712
  • egreg, thanks so much! but when pasted your solution, I had errors. Maybe because I should move some commands to the preamble and define some other commands. The errors I got are: 1) the single bracket in line 16 after (begin{tabular}) it gave this error (Illegal character in array arg).2) undefined control sequence \toprule line 17. 3)undefined control sequence lines 18& 19 & 21 & 25 & 26 & 29 & 32 . I will search for those error but please if you knew how to fix those errors post the answer here, thanks. – Naema Aug 14 '14 at 00:39
  • @Naema there is no error. Did you copy the code? the first error you mentioned, I get it, if one of the packages, in this case, siunitx is omitted. – doed Aug 14 '14 at 00:49
  • #doed thanks, I downloaded the package (siunitx) from CTAN and got red of the first error. I am searching the other errors now.yes, I copied the code. – Naema Aug 14 '14 at 02:35
  • oh, I seem to have so many missed packages. I downloaded (booktabs,si,siunitx). I still have three more errors but I do not think they are related to packages. here are the errors attached, can someone help me, please?. – Naema Aug 14 '14 at 03:08
  • I solved the error by downloading some missed packages when compiling with Latex. Thanks to all of you for helping!. The only remaining thing now is to add an extra column identical to (my results) column. I tried this my self and had an error. Maybe, I did a mistake because I am still learning how to build tables. I will post the MWE now, please help me. – Naema Aug 14 '14 at 10:01
  • I still do not get how to manipulate the code to get an extra column that looks the same as the (my results) column. Can someone help please? – Naema Aug 14 '14 at 15:41