0

I have three tables and I'm planning to organize them next to each other. I tried the code in this question but I couldn't even see any result!!

could someone advice me how to solve this issue?!

Thanks

 \begin{table}
                    \footnotesize
        \begin{tabular}{|c|c|c|c|}
        \hline
        \multicolumn{4}{|c|}{\textbf{Search Results}} \\

        \hline
         1 & D7 & R & $1.00$\\

         2 &  D2 & R&$1.00$\\

         3 & D3& NR& \\

         4 &  D5 &R& $0.75$\\

         5 & D1 &R& $0.8$ \\

         6 & D6 &NR&  \\

         7 &  D12 &R& $0.71$\\

         8 & D15 &NR& \\

         9 & D21 &NR& \\

         10 & D9 &R& $0.6$ \\
          \hline
         \multicolumn{3}{|c|}{\textbf{Avg}} & $0.810$ \\
         \hline
        \end{tabular}
                        \hfill
        \begin{table}[h]
        \centering
        \caption{Query Q2}
        \begin{tabular}{|c|c|c|c|}
        \hline
        \multicolumn{4}{|c|}{\textbf{Search Results}} \\

        \hline
         1 & D2 & R & $1.00$\\

         2 &  D1 & NR&\\

         3 & D3& NR& \\

         4 &  D5 &R& $0.5$\\

         5 & D7 &R& $0.6$ \\

         6 & D6 &NR&  \\

         7 &  D12 &NR& \\

         8 & D15 &NR& \\

         9 & D21 &R&$0.44$ \\

         10 & D9 &NR&  \\
          \hline
         \multicolumn{3}{|c|}{\textbf{Avg}} & $0.635$ \\
         \hline
        \end{tabular}
                        \hfill
        \begin{tabular}{|c|c|c|c|}
        \hline
        \multicolumn{4}{|c|}{\textbf{Search Results}} \\

        \hline
         1 & D12 & R & $1.00$\\

         2 &  D1 & NR&\\

         3 & D3& NR& \\

         4 &  D5 &NR& \\

         5 & D7 &R& $0.4$ \\

         6 & D6 &R& $0.5$ \\

         7 &  D2 &NR& \\

         8 & D15 &NR& \\

         9 & D21 &NR& \\

         10 & D9 &NR&  \\
          \hline
         \multicolumn{3}{|c|}{\textbf{Avg}} & $0.633$ \\
         \hline
        \end{tabular}

        \end{table}
1
  • 1
    Please can you add the complete source and a picture also with your hand what would you to obtain.
    – Sebastiano
    Jan 11 '17 at 11:10
2

You could put each tabular in a parbox:

\begin{table}[ht]
 \centering
    \parbox{.3 \textwidth}{
        \centering
        \begin{tabular}{|c|c|c|c|}
            \hline
            \multicolumn{4}{|c|}{\textbf{Search Results}} \\
            1 & D7 & R & $1.00$\\
            2 &  D2 & R&$1.00$\\
            \hline
        \end{tabular}
        \caption{My first table}
        \label{tab:1}
    }
    \hfill
    \parbox{.3 \textwidth}{
        \centering
        \begin{tabular}{|c|c|c|c|}
            \hline
            \multicolumn{4}{|c|}{\textbf{Search Results}} \\
            1 & D7 & R & $1.00$\\
            2 &  D2 & R&$1.00$\\
            2 &  D2 & R&$1.00$\\
            2 &  D2 & R&$1.00$\\
            \hline
        \end{tabular}
        \caption{My second table}
        \label{tab:2}
    }
    \hfill
    \parbox{.3 \textwidth}{
        \centering
        \begin{tabular}{|c|c|c|c|}
            \hline
            \multicolumn{4}{|c|}{\textbf{Search Results}} \\
            1 & D7 & R & $1.00$\\
            2 &  D2 & R&$1.00$\\
            \hline
        \end{tabular}
        \caption{My third table}
        \label{tab:3}
    }
 \end{table}

enter image description here

This does, unfortunately, not align the tables vertically if they have different heights.

Edit: As being pointed out by @Schweinebacke ad @Jan, you can align them using

\parbox[b]{.3 \textwidth}{
    \centering
    \begin{tabular}[t]{|c|c|c|c|}
    ...

enter image description here Also, you should read @Jan's answer concerning better formatting of your document.

8
  • 1
    You could use the optional argument of \parbox: [t] as in Top or [b] as in Bottom, to align the boxes and its enclosed tables. But you don't need to use the \parbox at all. Just insert the \tabular-environment directly in the cell.
    – Jan
    Jan 11 '17 at 11:21
  • 1
    It worked, I appreciate it @jmb really thanks!!
    – F 505
    Jan 11 '17 at 11:21
  • @Jan I tried using \parbox[t]{...} or \parbox[b]{...}, but it didn't work for me, they just stayed the same. Is it possible that the parbox shrinks around its content making Top, Bottom and Middle basically the same?
    – Fii
    Jan 11 '17 at 11:28
  • Try \parbox[t]{…} and \begin{tabular}[b]{…}. Jan 11 '17 at 11:29
  • @Jan Not using any parboxes doesn't work with captions and labels, I believe.
    – Fii
    Jan 11 '17 at 11:30
4

Regarding from your MWE, there is no second or third table, so I copied the existing one for two times, making three tables at all.

Nevertheless, you should use the booktabs-package and especially read its manual, as it explains the usage of lines in tables very well. I added this package and replaced your lines by them.

Second: use the array-package, in order to be able to use some stuff, that comes in very handy. Please also study the according manual. I used the \newcolumntype-command, to define new columns, save typing efforts and especially, being able to change the table layout with one effort in the preamble. I also used the >{} and <{} magic, to add an LaTeX-command, whenever you enter or leave a column, that those > and < are pointing at.

Third: Your last column contains math code. Therefore you added $...$ in your cells. You can avoid that repeated typing, by placing the column into math mode by using the >{$}c<{$} as I stated above and in the example on the new column C. But: in this special case, it makes a lot of sense, to use the dcolumn-package (read also that manual). By using a D-column, you are able, to justify the numbers according to the decimal separator sign (in your case the .. I defined the last column of the last table to be a D-column and its width according to 3 decimals.

Fourth: be careful, not to mix up the meaning of the tabular and the table-environment. The first will produce something, that looks like a table. The latter will produce something, that floats around, will be labeled with a table number and eventually be inserted in the List Of Tables. Inside the table-environment, you should use at least one tabular-environment, to typeset some content, that will look like an ordinary table.

In order to produce the table number, use the \caption-command. In order to reference that table in your text, use the \label- and \ref-commands.

Here is the code:

\documentclass[12pt,a4paper,twoside]{scrartcl}
\usepackage[utf8]{luainputenc}
\usepackage{array}
\usepackage{dcolumn}
\usepackage{booktabs}

%% save typing work, by defining this new columntype to be four
%% "c"-columns at a batch.  Added "@{}" to prevent additional left and
%% right empty margins at the table.   As the las column is always in
%% math mode, use the >{$}c<{$} trick, to make this a math mode
%% column.  Use *{3} to have three identical centered columns also.
\newcolumntype{C}{@{} *{3}{c} >{$}c<{$} @{}}
%% Same as above, but in this case, we are using a dcolumn column as
%% the last column.   The D-column is automatically in math mode.  You
%% have to define, how many decimals you want to store in that
%% column.   The alignment is adjusted to the decimal sign, in this
%% case the ".".
%% As column identifier D is already in use by dcolumns package, I
%% defined this new column to be called by "B".
\newcolumntype{B}{@{} *{3}{c} D{.}{.}{3} @{}}


\begin{document}
%% Create an floating environment.  Floating tables use to have a
%% caption, which is placed above the table.  Use \label and \ref to
%% reference on that table.
\begin{table}
  \caption{Some tables next to each other}
  \label{tab:some-tables}
  %% decreasing the font size is a bad idea!  
   \footnotesize
   %% Begin the first table
   \begin{tabular}{C}           % New column type, declared above
     %% New horizontal rule
     \toprule
     %% The table head is not the major player!  Be gentle, use a
     %% font, that is not that offensive, as \textbf
     \multicolumn{4}{c}{\textit{Search Results}} \\
     %% Again, the much nicer looking rule type
     \midrule
     1 & D7 & R & 1.00\\
     2 &  D2 & R&1.00\\
     3 & D3& NR& \\
     4 &  D5 &R& 0.75\\
     5 & D1 &R& 0.8 \\
     6 & D6 &NR&  \\
     7 &  D12 &R& 0.71\\
     8 & D15 &NR& \\
     9 & D21 &NR& \\
     10 & D9 &R& 0.6 \\
     \midrule
     \multicolumn{3}{c}{\textit{Avg}} & 0.810 \\
     %% last of the cute new lines types
     \bottomrule
   \end{tabular}
   \hfill
   %% Second table.   Cut and pasted from the table No. 1
   \begin{tabular}{C}
     \toprule
     \multicolumn{4}{c}{\textit{Search Results}} \\
     \midrule
     1 & D7 & R & 1.00\\
     2 &  D2 & R&1.00\\
     3 & D3& NR& \\
     4 &  D5 &R& 0.75\\
     5 & D1 &R& 0.8 \\
     6 & D6 &NR&  \\
     7 &  D12 &R& 0.71\\
     8 & D15 &NR& \\
     9 & D21 &NR& \\
     10 & D9 &R& 0.6 \\
     \midrule
     \multicolumn{3}{c}{\textit{Avg}} & 0.810 \\
     \bottomrule
   \end{tabular}
   \hfill
   %% Third and last table, also C&P!
   \begin{tabular}{B}
     \toprule
     \multicolumn{4}{c}{\textit{Search Results}} \\
     \midrule
     1 & D7 & R & 1.00\\
     2 &  D2 & R&1.00\\
     3 & D3& NR& \\
     4 &  D5 &R& 0.75\\
     5 & D1 &R& 0.8 \\
     6 & D6 &NR&  \\
     7 &  D12 &R& 0.71\\
     8 & D15 &NR& \\
     9 & D21 &NR& \\
     10 & D9 &R& 0.6 \\
     \midrule
     \multicolumn{3}{c}{\textit{Avg}} & 0.810 \\
     \bottomrule
   \end{tabular}
 \end{table}

There are some tables next to each other, as presented in
table~\ref{tab:some-tables}. 
\end{document}

And this is the result:

enter image description here

3

Package threeparttable can be used to set serveral table beside each other with well aligned captions:

\documentclass{article}
\usepackage{threeparttable}
\begin{document}
\begin{table}[ht]
 \centering
 \begin{threeparttable}
   \begin{tabular}[b]{|c|c|c|c|}
     \hline
     \multicolumn{4}{|c|}{\textbf{Search Results}} \\
     1 & D7 & R & $1.00$\\
     2 &  D2 & R&$1.00$\\
     \hline
   \end{tabular}
   \caption{My first table}
   \label{tab:1}
 \end{threeparttable}
 \hfill
 \begin{threeparttable}
   \begin{tabular}[b]{|c|c|c|c|}
     \hline
     \multicolumn{4}{|c|}{\textbf{Search Results}} \\
     1 & D7 & R & $1.00$\\
     2 &  D2 & R&$1.00$\\
     2 &  D2 & R&$1.00$\\
     2 &  D2 & R&$1.00$\\
     \hline
   \end{tabular}
   \caption{My second table}
   \label{tab:2}
 \end{threeparttable}
 \hfill
 \begin{threeparttable}
   \begin{tabular}[b]{|c|c|c|c|}
     \hline
     \multicolumn{4}{|c|}{\textbf{Search Results}} \\
     1 & D7 & R & $1.00$\\
     2 &  D2 & R&$1.00$\\
     \hline
   \end{tabular}
   \caption{My third table}
   \label{tab:3}
 \end{threeparttable}
 \end{table}

\end{document}

caption below table

It can be used also with usual captions above tables:

\documentclass{article}
\usepackage{caption}
\usepackage{threeparttable}
\begin{document}
\begin{table}[ht]
 \centering
 \begin{threeparttable}
   \caption{My first table}
   \begin{tabular}[b]{|c|c|c|c|}
     \hline
     \multicolumn{4}{|c|}{\textbf{Search Results}} \\
     1 & D7 & R & $1.00$\\
     2 &  D2 & R&$1.00$\\
     \hline
   \end{tabular}
   \label{tab:1}
 \end{threeparttable}
 \hfill
 \begin{threeparttable}
   \caption{My second table}
   \begin{tabular}[b]{|c|c|c|c|}
     \hline
     \multicolumn{4}{|c|}{\textbf{Search Results}} \\
     1 & D7 & R & $1.00$\\
     2 &  D2 & R&$1.00$\\
     2 &  D2 & R&$1.00$\\
     2 &  D2 & R&$1.00$\\
     \hline
   \end{tabular}
   \label{tab:2}
 \end{threeparttable}
 \hfill
 \begin{threeparttable}
   \caption{My third table}
   \begin{tabular}[b]{|c|c|c|c|}
     \hline
     \multicolumn{4}{|c|}{\textbf{Search Results}} \\
     1 & D7 & R & $1.00$\\
     2 &  D2 & R&$1.00$\\
     \hline
   \end{tabular}
   \label{tab:3}
 \end{threeparttable}
 \end{table}

\end{document}

caption above table

If the tables are related you can use the subcaption package:

\documentclass{article}
\usepackage{subcaption}
\usepackage{threeparttable}
\begin{document}
\begin{table}[ht]
  \centering
  \caption{Three related tables}\label{tab:all}
  \subcaptionbox{My first table\label{tab:1}}{%
    \begin{tabular}[b]{|c|c|c|c|}
      \hline
      \multicolumn{4}{|c|}{\textbf{Search Results}} \\
      1 & D7 & R & $1.00$\\
      2 &  D2 & R&$1.00$\\
      \hline
    \end{tabular}
  }
  \subcaptionbox{My second table\label{tab:2}}{%
    \begin{tabular}[b]{|c|c|c|c|}
      \hline
      \multicolumn{4}{|c|}{\textbf{Search Results}} \\
      1 & D7 & R & $1.00$\\
      2 &  D2 & R&$1.00$\\
      2 &  D2 & R&$1.00$\\
      2 &  D2 & R&$1.00$\\
      \hline
    \end{tabular}
  }
  \subcaptionbox{My third table\label{tab:3}}{%
    \begin{tabular}[b]{|c|c|c|c|}
      \hline
      \multicolumn{4}{|c|}{\textbf{Search Results}} \\
      1 & D7 & R & $1.00$\\
      2 &  D2 & R&$1.00$\\
      \hline
    \end{tabular}
  }
\end{table}
\end{document}

using subcaption

3
  • This is a good answer especially regarding the subcaptions.
    – Jan
    Jan 11 '17 at 16:20
  • @Jan: Thanks. It could be better (using nice tables with booktabs like you've done), but I'm too lazy. Jan 11 '17 at 17:06
  • But it was nevertheless instructive!
    – Jan
    Jan 11 '17 at 17:15

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.