-2

I would like to create a table like the one I show in the image but I'm a bit lost.

enter image description here

Let's see if someone can help me.

Thank you.

4
  • 3
    welcome to tex.se! for start see en.wikibooks.org/wiki/LaTeX/Tables. also look for answers on question tagged as tables. here on site are tons of similar question.
    – Zarko
    Commented Jan 12, 2019 at 10:33
  • 2
    For 'number of operations' take a look ath the \multicolumn command and for 'Database' you might want to have a look at the \multirow command.
    – leandriis
    Commented Jan 12, 2019 at 10:44
  • 3
    The answers to Using multicolumn in latex and How to use \multirow might give you an idea on how to use the above mentioned commands. Apart from that, please show what you tried so far by including a minimal working example (MWE) to your question.
    – leandriis
    Commented Jan 12, 2019 at 10:59
  • 4
    Are you mainly interested in reproducing the boring table shown in the screenshot exactly as is, or might you be interested in learning how to show the tabular information in a more appealing and inviting way?
    – Mico
    Commented Jan 12, 2019 at 12:22

3 Answers 3

5

Here's a solution which uses the l column type for the first column and the r column type for the six data columns. To give the table material a more open "look", no vertical lines are drawn, and the line-drawing macros of the booktabs package are used in place of \hline and \cline.

enter image description here

\documentclass{article}
\usepackage{booktabs} % for well-spaced horizontal rules
\begin{document}

\begin{center}
\begin{tabular}{@{} l *{6}{r} @{}} % "@{}" eliminates horizontal whitespace padding.
\toprule
Database & \multicolumn{6}{c@{}}{Number of operations} \\
\cmidrule(l){2-7}
        &  10 &  50 &  100 & 1000 & 10000 & 100000 \\
\midrule
MongoDB &  61 &  75 &   84 &  387 &  2693 &  23354 \\ 
RavenDB & 570 & 898 & 1213 & 6939 & 71343 & 740450 \\ 
\ldots\\
MS Sql Express & 30 & 94 & 129 & 1790 & 15588 & 216479 \\
\bottomrule
\end{tabular}
\end{center}
\end{document}
4

In addition to novski's answer, here is a variant using rules from booktabs for a more open appearance and siunitx for better alignment of number.

\documentclass{article}
\usepackage{multirow}
\usepackage[group-minimum-digits=4]{siunitx}
\usepackage{booktabs}

\begin{document}

\begin{tabular}{l
                 S[table-format=3]
                 S[table-format=3]
                 S[table-format=4]
                 S[table-format=4]
                 S[table-format=5]
                 S[table-format=6]}
  \toprule
  \multirow{2.5}{*}{Database} & \multicolumn{6}{c}{Number of operations} \\
  \cmidrule{2-7}
                    & 10 & 50 & 100 & 1000 & 10000 & 100000\\
  \midrule
  MongoDB           & 61 & 75 & 84 & 387 & 2693 & 23354 \\ 
  RavenDB           & 570 & 898 & 1213 & 6939 & 71343 & 740450 \\ 
  \bottomrule
\end{tabular}

\end{document}

enter image description here


Here is the variant without the \multirow:

 \toprule
 Database & \multicolumn{6}{c}{Number of operations} \\
 \cmidrule{2-7}

enter image description here

4
  • 1
    You may want to add the siunitx option group-minimum-digits=4 to avoid some unevenness across rows.
    – Mico
    Commented Jan 12, 2019 at 14:13
  • In addition to group-minimum-digits=4, the last column should have S[table-format=7]. I'd not use \multirow, as the upper left cell has no reason for being lowered, being a first level header.
    – egreg
    Commented Jan 12, 2019 at 14:35
  • @Mico: Thanks for your suggestion. I have implemented into the answer.
    – leandriis
    Commented Jan 12, 2019 at 15:29
  • @egreg: Thanks for your correction and suggestion as well. I have implemened both in the answer.
    – leandriis
    Commented Jan 12, 2019 at 15:29
0

i use this dependencies:

\usepackage{longtable}
\usepackage{multirow}

~

\begin{longtable}{|l|c|c|c|c|c|c|}\hline
  \multirow{2}{*}{Database} & \multicolumn{6}{c|}{Number of operations} \\\cline{2-7}
                    & 10 & 50 & 100 & 1000 & 10000 & 1000000\\\hline\endhead
  MongoDB           & 61 & 75 & 84 & 387 & 2693 & 23354 \\ 
  RavenDB           & 570 & 898 & 1213 & 6939 & 71343 & 740450 \\ \hline
\caption{Database evaluation}
\label{tab:databaseeval}
\end{longtable}

picturewithcaption

6
  • 3
    Why do you usa a longtable? The table in the question seems to be short enought to fit onto a single page.
    – leandriis
    Commented Jan 12, 2019 at 12:28
  • i use longtable for everything because it wraps the environement 'table' and lets you directly write the caption and label in to the begin without doubling the env. like table-tabular. i will add that to the sample.
    – novski
    Commented Jan 12, 2019 at 12:31
  • 4
    "longtable is not a floating environment." (See: tex.stackexchange.com/a/215443/134144) You might want to keep that in mind when using longtable.
    – leandriis
    Commented Jan 12, 2019 at 12:39
  • In the OP's screenshot, the numbers in the six data columns are right-aligned, not centered. You may want to mention how the OP could get right-aligned numbers.
    – Mico
    Commented Jan 12, 2019 at 14:05
  • 2
    You wrote "i use longtable for everything because it wraps the environement 'table' ." What if the table is fairly short (as is the case here) and should not, under any circumstance, be broken across pages?
    – Mico
    Commented Jan 12, 2019 at 14:22

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