Skip to main content

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Asked
Viewed 14k times
14

I want to render a table with results of experiments. There are 6 experiments (multirows) described by 2 columns and each of them is performed 5 times (rows).

My code:

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

This code produces what I want only for the first row:

The output of above code

successful rows after the first one are shifted and overlapping the "8" number. Can you please help me?

0

2 Answers 2

17

I believe your problem is that you didn't put enough empty cells for the following lines. A multirow will allow content to occupy space, but doesn't actually create the cells that are under it. I rewrote your code aligning everything to illustrate that.

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

You may also typeset the table without multicols, using nested tabular. The nested tabulars are put inside two new commands, \splitl and \splitr.

The main tabular is set using tabular*, to ensure better distribution of space. The benefit using nested table is that LaTeX does most of the calculation.

To improve readability, I suggest that you consider to remove most of the vertical line (see example 2).

tabular* and hline

enter image description here

\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* and booktabs

enter image description here

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.