如何获取表中的多个多行?

如何获取表中的多个多行?

我想绘制一个包含实验结果的表格。表格中有 6 个实验(多行),每行由 2 列描述,每个实验执行 5 次(行)。

我的代码:

\begin{表格}{lr | l || rr}
数学 & 数学 & 算法 & 数学 & 数学 \\ \hline
\multirow{5}{*}{加布里埃尔} & \multirow{5}{*}{8}
& 朴素二进制 & 158 & 44 \& 朴素二进制_LCP & 174 & 92 \& 朴素插值 & 168 & 78 \& LESS 朴素二进制 & 98 & 26 \& LESS 朴素二进制_LCP & 124 & 58 \\ \hline
...
\end{表格}

此代码仅生成我想要的第一行的内容:

上述代码的输出

第一行之后的成功行被移动并与“8”数字重叠。你能帮助我吗?

答案1

我认为您的问题是您没有为以下行放置足够的空单元格。多行将允许内容占据空间,但实际上不会创建其下方的单元格。我重写了您的代码,对齐所有内容以说明这一点。

\begin{tabular}{l r | l || r r}
Vzorka & Výskyty & Algoritmus & Porovnania & Prístupy \\ \hline 
\multirow{5}{*}{Gabriel} & \multirow{5}{*}{8} & NAIVE BINARY          & 158   & 44 \\
                         &                    & NAIVE BINARY_LCP      & 174   & 92 \\
                         &                    & NAIVE INTERPOLATION   & 168   & 78 \\
                         &                    & LESS NAIVE BINARY     & 98    & 26 \\
                         &                    & LESS NAIVE BINARY_LCP & 124   & 58 \\ \hline
\end{tabular}

答案2

您也可以排版表格而不多色,使用嵌套表格。嵌套表格放在两个新命令\splitl和中\splitr

使用 设置主表格tabular*,以确保更好地分配空间。使用嵌套表的好处是 LaTeX 会完成大部分计算。

为了提高可读性,我建议您考虑删除大部分垂直线(参见示例 2)。

tabular*hline

在此处输入图片描述

\documentclass{article}
\usepackage{array}

\setlength{\extrarowheight}{1pt}
\setlength{\tabcolsep}{3pt}
\renewcommand*{\arraystretch}{1.1}

% Multi-line left-aligned text with manual line breaks.
% The base line is in centre.
\newcommand*{\splitl}[1]{%
\begingroup
    \renewcommand*{\arraystretch}{1.1}%
    \begin{tabular}[c]{@{}l@{}}#1\end{tabular}%
  \endgroup
}

% Multi-line right-aligned text with manual line breaks.
% The base line is in centre.

\newcommand*{\splitr}[1]{%
\begingroup
    \renewcommand*{\arraystretch}{1.1}%
    \begin{tabular}[c]{@{}r@{}}#1\end{tabular}%
  \endgroup
}

\newcommand{\smb}{\small\bfseries}


\begin{document}


\noindent\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}|l c | l ||rr|}

\smb Vzorka & \smb Výskyty & \smb Algoritmus & \smb Porovnania & \smb Prístupy \\ \hline 
Gabriel & 8 &\splitl{NAIVE BINARY \\
                                   NAIVE BINARY \\
                                   NAIVE INTERPOLATION\\
                                   LESS NAIVE BINARY \\
                                   LESS NAIVE BINARY\_LCP
                                   } & 
                                   \splitr{158 \\
                                           174 \\
                                           168 \\
                                           98  \\
                                           124} &
                                           \splitr{44\\
                                                      92\\
                                                      78\\
                                                      26 \\
                                                      59
                                                      }\\

\hline
``father'' & 8 &\splitl{NAIVE BINARY \\
                                   NAIVE BINARY \\
                                   NAIVE INTERPOLATION\\
                                   LESS NAIVE BINARY \\
                                   LESS NAIVE BINARY\_LCP
                                   } & 
                                   \splitr{202 \\
                                           187 \\
                                           101 \\
                                           179  \\
                                           169} &
                                           \splitr{45\\
                                                      94\\
                                                      40\\
                                                      37 \\
                                                      80
                                                      }\\

\hline
``God'' & 8    &\splitl{NAIVE BINARY \\
                                   NAIVE BINARY \\
                                   NAIVE INTERPOLATION\\
                                   LESS NAIVE BINARY \\
                                   LESS NAIVE BINARY\_LCP
                                   } & 
                                   \splitr{142 \\
                                           154 \\
                                          2472 \\
                                           119  \\
                                           128} &
                                           \splitr{45\\
                                                    94\\
                                                  1240\\
                                                    35 \\
                                                    76
                                                      }\\

\hline
``Mary'' & 8    &\splitl{NAIVE BINARY \\
                                   NAIVE BINARY \\
                                   NAIVE INTERPOLATION\\
                                   LESS NAIVE BINARY \\
                                   LESS NAIVE BINARY\_LCP
                                   } & 
                                   \splitr{147 \\
                                           154 \\
                                           191 \\
                                           106 \\
                                           115} &
                                           \splitr{45\\
                                                      94\\
                                                      88\\
                                                      29\\
                                                      64
                                                      }\\

\hline
``Ezechiel'' & 8    &\splitl{NAIVE BINARY \\
                                   NAIVE BINARY \\
                                   NAIVE INTERPOLATION\\
                                   LESS NAIVE BINARY \\
                                   LESS NAIVE BINARY\_LCP
                                   } & 
                                   \splitr{175 \\
                                           181 \\
                                           886 \\
                                           133 \\
                                           142} &
                                           \splitr{44\\
                                                      92\\
                                                     230\\
                                                      28\\
                                                      63
                                                      }\\

\hline
\end{tabular*}
\end{document} 

tabular*书签

在此处输入图片描述

\documentclass{article}
\usepackage{array, booktabs}

\setlength{\extrarowheight}{1pt}
\setlength{\tabcolsep}{3pt}
\renewcommand*{\arraystretch}{1.1}

% Multi-line left-aligned text with manual line breaks.
% The base line is in centre.
\newcommand*{\splitl}[1]{%
\begingroup
    \renewcommand*{\arraystretch}{1.1}%
    \begin{tabular}[c]{@{}l@{}}#1\end{tabular}%
  \endgroup
}

% Multi-line right-aligned text with manual line breaks.
% The base line is in centre.

\newcommand*{\splitr}[1]{%
\begingroup
    \renewcommand*{\arraystretch}{1.1}%
    \begin{tabular}[c]{@{}r@{}}#1\end{tabular}%
  \endgroup
}

\newcommand{\smb}{\small\bfseries}


\begin{document}

\noindent\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}l c  l  rr@{}}

\toprule
\smb Vzorka & \smb Výskyty & \smb Algoritmus & \smb Porovnania & \smb Prístupy \\ \midrule 
Gabriel & 8 &\splitl{NAIVE BINARY \\
                                   NAIVE BINARY \\
                                   NAIVE INTERPOLATION\\
                                   LESS NAIVE BINARY \\
                                   LESS NAIVE BINARY\_LCP
                                   } & 
                                   \splitr{158 \\
                                           174 \\
                                           168 \\
                                           98  \\
                                           124
                                           } &
                                           \splitr{44\\
                                                   92\\
                                                   78\\
                                                   26\\
                                                   59
                                               }\\

\midrule
``father'' & 8 &\splitl{NAIVE BINARY \\
                                   NAIVE BINARY \\
                                   NAIVE INTERPOLATION\\
                                   LESS NAIVE BINARY \\
                                   LESS NAIVE BINARY\_LCP
                                   } & 
                                   \splitr{202 \\
                                           187 \\
                                           101 \\
                                           179  \\
                                           169} &
                                           \splitr{45\\
                                                   94\\
                                                   40\\
                                                   37 \\
                                                   80
                                                }\\

\midrule
``God'' & 8    &\splitl{NAIVE BINARY \\
                                   NAIVE BINARY \\
                                   NAIVE INTERPOLATION\\
                                   LESS NAIVE BINARY \\
                                   LESS NAIVE BINARY\_LCP
                                   } & 
                                   \splitr{142 \\
                                           154 \\
                                          2472 \\
                                           119  \\
                                           128} &
                                           \splitr{45\\
                                                   94\\
                                                  1240\\
                                                    35\\
                                                    76
                                                }\\

\midrule
``Mary'' & 8    &\splitl{NAIVE BINARY \\
                                   NAIVE BINARY \\
                                   NAIVE INTERPOLATION\\
                                   LESS NAIVE BINARY \\
                                   LESS NAIVE BINARY\_LCP
                                   } & 
                                   \splitr{147 \\
                                           154 \\
                                           191 \\
                                           106  \\
                                           115} &
                                           \splitr{45\\
                                                   94\\
                                                   88\\
                                                   29\\
                                                   64
                                                }\\

\midrule
``Ezechiel'' & 8    &\splitl{NAIVE BINARY \\
                                   NAIVE BINARY \\
                                   NAIVE INTERPOLATION\\
                                   LESS NAIVE BINARY \\
                                   LESS NAIVE BINARY\_LCP
                                   } & 
                                   \splitr{175 \\
                                           181 \\
                                           886 \\
                                           133 \\
                                           142} &
                                           \splitr{44\\
                                                   92\\
                                                  230\\
                                                   28\\
                                                   63
                                                }\\

\bottomrule
\end{tabular*}
\end{document} 

相关内容