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

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

  • 2
    Off-topic: You have some questions with answers, please consider accepting them before piling up further questions ;-) – user31729 Aug 13 '14 at 20:14
  • 2
    have a look at multicolumn, play with it for a while, then have a look at multirow and try to incorporate it slowly.... :) start small, and build up until you get closer :) – cmhughes Aug 13 '14 at 20:15
  • can someone give me an example of how to create a table in Latex report with using multicolumn and multirow? – Naema Aug 13 '14 at 20:43
  • Yesterday I recommended you to read this in fact, the section 1.7 could be helpful for you. Take a look at this question also in the documentation of the package. – Aradnix Aug 16 '14 at 6:53
  • @Naema Here is the multicol package a classic. Please check the package documentation, would be useful for you. – Aradnix Aug 16 '14 at 9:04
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

| improve this answer | |
  • 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 0: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 0: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 2: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 3: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

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.