一排表格

一排表格

我有三张桌子,我打算把它们并排摆放。我尝试了以下代码 这个问题但我甚至看不到任何结果!!

有人可以告诉我如何解决这个问题吗?!

谢谢

 \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

你可以把每一个tabular放在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

不幸的是,如果表格高度不同,则无法垂直对齐表格。

编辑: 正如@Schweinebacke 和@Jan 指出的那样,你可以使用

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

enter image description here 此外,您应该阅读@Jan 的回答,了解有关更好地格式化文档的信息。

答案2

关于您的 MWE,没有第二或第三个表格,所以我将现有表格复制了两次,总共制作了三个表格。

尽管如此,你应该使用booktabs-package,特别是阅读它的手动的,因为它很好地解释了表格中线条的用法。我添加了这个包并用它们替换了你的线条。

第二:使用array-package,以便能够使用一些非常方便的东西。还请研究相应的手动的。我使用了\newcolumntype-命令来定义新列,节省了输入工作量,尤其是能够在序言中一举更改表格布局。我还使用了>{}<{}魔法,每当您进入或离开列时,都会添加 LaTeX 命令,这些><指向该列。

第三:最后一列包含数学代码。因此,您在单元格中添加了$...。您可以避免重复输入,方法是使用我上面和新列示例中所述的方式将列置于数学模式。但是:在这种特殊情况下,使用 -package 非常有意义(另请阅读$>{$}c<{$}Cdcolumn手动的)。通过使用D-column,您可以根据小数分隔符(在您的情况下为)对齐数字.。我将最后一个表格的最后一列定义为 -column D,并将其宽度按照 3 位小数对齐。

第四:要小心,不要混淆tabulartable环境的含义。前者会产生一些看起来像表格的东西。后者会产生一些浮动的东西,会标有表格编号,最终会插入到表格列表中。在环境中table,您应该至少使用一个tabular环境来排版一些看起来像普通表格的内容。

要生成表格编号,请使用\caption-命令。要在文本中引用该表格,请使用\label- 和\ref-命令。

以下是代码:

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

结果如下:

enter image description here

答案3

包裹threeparttable可用于将多个表格并排放置,并带有对齐的标题:

\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

它也可以与表格上方的常用标题一起使用:

\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

如果表是相关的,您可以使用subcaption包裹:

\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

相关内容