0

I want to build a table but it is specific. Can u guys help me with that problem?

Table1,2

I know I have to use table and tabular, but I don't know how to put the dashes under dataset and under n=1 and so on.

And I don't want to have those grey and white background colors in the table, because I don't know :P.

\documentclass[a4paper, 12pt,fleqn]{article} 
 \usepackage[left=30mm,right=40mm,top=25mm,bottom=20mm, includeheadfoot]    
  {geometry}%centering hinter headfoot
 \usepackage[ngerman]{babel}
 \usepackage[rm={tabular, lining},sf={tabular, lining},tt={monowidth, tabular,  
   lining}]{cfr-lm}
  \usepackage[onehalfspacing]{setspace}     
 \pagestyle{myheadings}
 \usepackage{courier}
  \renewcommand*\familydefault{\sfdefault} %Schriftart geändert
    \usepackage{booktabs}

 \begin{document}
  \begin{table}[htbp]
 \centering
   \begin{tabular}{ccccccccccc}
 Data set-1 for the example problem\\
 \midrule
 1& \
 1&0&&&1&4&&1&6\
  \end{tabular}
  \label{default}
 \end{table} 
\end{document}
6
  • You don't want alternating colours?
    – Bernard
    Commented Jan 4, 2017 at 19:42
  • @Bernard its hard for me to build the table even without alternating colors-.-
    – Milo Li
    Commented Jan 4, 2017 at 19:44
  • you only need the table environment if you want the table to float.
    – jakun
    Commented Jan 4, 2017 at 19:58
  • 1
    if you want to typeset a german document I recommend to use (additionally to \usepackage[ngerman]{babel} which you already have): \usepackage[utf8]{inputenc} for being able to insert umlaute directly, \usepackage[T1]{fontenc} for being able to copy and paste umlaute from the pdf and hyphenate words containing umlaute and \usepackage{lmodern} because the font used by T1 fontenc looks not so nice and ligatures could not be copied and pasted from the pdf.
    – jakun
    Commented Jan 4, 2017 at 20:05
  • I think, you should change the title of this question, as you wanted to have lines in your table, don't you?
    – Jan
    Commented Jan 4, 2017 at 20:20

2 Answers 2

2

An alternative solution using cmidrule from booktabs:

\documentclass[a4paper, 12pt,fleqn]{article} 
\usepackage[left=30mm,right=40mm,top=25mm,bottom=20mm, includeheadfoot]    
     {geometry}%centering hinter headfoot
\usepackage[ngerman]{babel}
\usepackage[rm={tabular, lining}, sf={tabular, lining},
             tt={monowidth, tabular, lining}]{cfr-lm}
\usepackage[onehalfspacing]{setspace}     
\pagestyle{myheadings}
\usepackage{courier}
\renewcommand*\familydefault{\sfdefault} %Schriftart geändert
\usepackage{booktabs}

\begin{document}
\begin{table}[htbp]
\centering
\begin{tabular}{cccccccc}
\multicolumn{8}{l}{Data set-1 for the example problem}\\
\toprule
 & & \multicolumn{6}{c}{Job}\\
 Stage & Machine & \multicolumn{3}{c}{$n=1$} & 
 \multicolumn{3}{c}{$n=2$}\\
 \cmidrule(lr){3-5}\cmidrule(l){6-8}
 $i$ & $m$ & 
 $S_{m,i,n,0}$ & $S_{m,i,n,1}$ & $S_{m,i,n,2}$ &  
 $S_{m,i,n,0}$ & $S_{m,i,n,1}$ & $S_{m,i,n,2}$ \\
 \midrule
   1& 1&40&15&60&30&70&10\\
   \bottomrule
\end{tabular}
\label{default}
\end{table} 
\end{document}

enter image description here

5
  • WOW! Thank you very much, i try to work with that =)
    – Milo Li
    Commented Jan 4, 2017 at 19:55
  • is there a way to combine the line under n=1 and n=2 to one line ?
    – Milo Li
    Commented Jan 4, 2017 at 19:57
  • @MiloLi: Yes, replace \cmidrule(lr){3-5}\cmidrule(l){6-8} by \cmidrule{3-8}. You can also read booktabs documentation to understand how options like (lr) change the result.
    – Ignasi
    Commented Jan 4, 2017 at 20:00
  • These are new questions. You can start them and make reference to this one. In any case I think you already found them answered here after a little search.
    – Ignasi
    Commented Jan 4, 2017 at 20:26
  • i found the asnwers! but can you tell me how do i put my table in colors like grey and white? i just see rows and colors in other examples, but how can i put complete stage 1 in table 1 in grey?
    – Milo Li
    Commented Jan 4, 2017 at 20:39
1

I had a similar question yesterday and the answer was the hhline package in my case.

So it may help you too:

\usepackage{hhline}
%% ...

\begin{tabular}{ccccccccccc}
 \multicolumn{7}{l}Data set-1 for the example problem}\\ \hline
 1& \
  1&0&&&1&4&&1&6\ \\
 \hhline{~----------}
  1& \
  1&0&&&1&4&&1&6\
  \end{tabular}

enter image description here

~ is for no line at that column
- is for a line at that column

there should be as much chars as in the tabular definition itself.


[edit]

This gets closer to your initial example. The vertical rules are just to demonstrate the centering of the multi column cells.

   \begin{tabular}{ccccccccccc}
    \multicolumn{7}{l}{Data set-1 for the example problem}\\ \hline
        \multicolumn{2}{c}{} & \multicolumn{6}{|c|}{job}\\
        Stage & Mashine & \multicolumn{3}{|c|}{n = 1} & \multicolumn{3}{|c|}{n = 2}\\
% Data set-1 for the example problem\\
 %\midrule
 \hhline{~~---------}
 1& \
 1&0&22222222&3&1&4&5&1&6&6\ \\ \hline
 1& \
 1&00000000&2&3&111111111111&4&5555555555&1&6&6 \\
  \end{tabular}

enter image description here

3
  • i get an error when i build in your features.
    – Milo Li
    Commented Jan 4, 2017 at 19:43
  • ! Missing \cr inserted.
    – Milo Li
    Commented Jan 4, 2017 at 19:47
  • I see, I put \hhline at the wrong position, I update the answer. Commented Jan 4, 2017 at 19:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .