# How to draw a multirow table?

I am new to Latex and need help drawing tables. Here is what I have right now:

and here is the code for it:

\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
Topology & Average Delay(s) & Average Bandwidth(kbps) & Hosts \\
\hline
Low & 0.0994 & 2441.85 & \multirow{2}{*}{64} \\
High & 0.1424 & 2515.77  \\
\hline
Low & 0.2522 & 1798.60 & \multirow{2}{*}{128} \\
High & 0.1113 & 2123.17  \\
\hline
\caption{This table shows}
\label{eval_table}
\end{tabular}
\end{center}


Here is is what I want to do:

1) Shrink the table width so that it matches the column width

2) Fix the last vertical line

3) Set up the caption properly

I have spent hours on this and I don't know how to fix it.

-
FWIW, don't use vertical rules in tables. See page 3 of the booktabs manual. –  You Jul 18 '12 at 9:10
Please provide information on the width of the textblock. I'm afraid it's not possible to tell this important piece of information from your code fragment. –  Mico Jul 18 '12 at 9:14
As you said you are new to LaTeX, maybe you do not yet know there exist tools like excel2latex that make producing tables a lot easier. Most of those tools are discussed in this question: tex.stackexchange.com/questions/49414/… –  matth Jul 18 '12 at 11:53
@matth: Thanks for the link –  Bruce Jul 18 '12 at 16:12
@Mico: The width of the text block is the standard two column width used by IEEE conference papers –  Bruce Jul 18 '12 at 16:13

I'm afraid that because you've provided only a code snippet rather than a full MWE (minimum working example), some vital information -- the width of the text block of your document -- is not available. I've thus had to make some (possibly incorrect) assumptions: A4 paper size, 1-inch margins, two-column mode.

Below is a succession of tables that address various issues you raise. I've deliberately not centered the tables to make it easier to compare the widths of the tables. (In a real document, you should of course encase each tabular environment inside \begin{table} \caption{...} \label{...} \centering [tabular stuff] \end{table} statements.) First, there's a horizontal rule indicating the width of the text block. In the first table, the missing vertical lines are restored by adding a couple of & symbols. Obviously, the table is (much) too wide and won't fit in the available space.

In the second table, the widths of columns 2 and 3 are reduced significantly by moving the unit designations to separate lines. (This should also help reduce any confusion over whether the (s) after Delay is a unit designation or the plural-s to Delay.) In the third table, the width is reduced further, succeeding in making the table fit in the text block. Importantly, all vertical lines are eliminated, allowing some more (horizontal) space saving; in addition, the look of the horizontal lines and the spacing above and below the horizontal lines is improved by replacing the basic LaTeX \hline macro with \toprule, \midrule, and \bottomrule macros.

\documentclass[a4paper,twocolumn]{article}
\usepackage[margin=1in]{geometry}
\usepackage{multirow,booktabs}
\setlength\parindent{0pt}
\begin{document}
Width of text block, two-column mode:
\hrule
\bigskip
(a) Restore the missing vertical lines:

\smallskip
\begin{tabular}{|c|c|c|c|}
\hline
Topology & Average Delay(s) & Average Bandwidth(kbps) & Hosts \\
\hline
Low & 0.0994 & 2441.85 & \multirow{2}{*}{64} \\
High & 0.1424 & 2515.77  & \\
\hline
Low & 0.2522 & 1798.60 & \multirow{2}{*}{128} \\
High & 0.1113 & 2123.17  & \\
\hline
\end{tabular}

\bigskip
(b) Reduce table width by moving units designations
to separate line:

\smallskip
\begin{tabular}{|c|c|c|c|}
\hline
Topology & Average Delay & Average Bandwidth & Hosts \\
& (s) & (kbps) & \\
\hline
Low & 0.0994 & 2441.85 & \multirow{2}{*}{64} \\
High & 0.1424 & 2515.77  & \\
\hline
Low & 0.2522 & 1798.60 & \multirow{2}{*}{128} \\
High & 0.1113 & 2123.17  & \\
\hline
\end{tabular}

\bigskip
(c) Better horizontal lines, no vertical lines, reduce table
width some more:

\smallskip
\begin{tabular}{@{} cccc @{}}
\toprule
Topology & Avg.\ Delay & Avg.\ Bandwidth & Hosts \\
& (s) & (kbps) & \\
\midrule
Low & 0.0994 & 2441.85 & \multirow{2}{*}{64} \\
High & 0.1424 & 2515.77  & \\[2ex]
Low & 0.2522 & 1798.60 & \multirow{2}{*}{128} \\
High & 0.1113 & 2123.17  & \\
\bottomrule
\end{tabular}

\end{document}

-

1. Vertical line

Just add an extra ampersand after the column definition, that'll fix the vertical line. e.g.,

Low & 0.0994 & 2441.85 & \multirow{2}{*}{64} \\
High & 0.1424 & 2515.77 & \\


The extra vertical lines at the end are addressed by moving the \label block.

1. Caption

The tabular environment, afaik, normally doesn't support captions. You may want to envelope all this with the \begin{table}...\end{table} and place the \caption{Table} after closing the tabular environment.

So, the complete code looks like:

\begin{table}
\centering
\begin{tabular}{|c|c|c|c|}
\hline
Topology & Average Delay(s) & Average Bandwidth(kbps) & Hosts \\
\hline
Low & 0.0994 & 2441.85 & \multirow{2}{*}{64} \\
High & 0.1424 & 2515.77 & \\
\hline
Low & 0.2522 & 1798.60 & \multirow{2}{*}{128} \\
High & 0.1113 & 2123.17 & \\
\hline
\end{tabular}
\caption{This table shows}\label{eval_table}
\end{table}


producing the following output:

UPD: made some corrections pointed by egreg

-
Never include table in a center environment; rather declare \centering after \begin{table}. The \label should go after \caption –  egreg Jul 18 '12 at 9:48
@egreg, Thanks, I've corrected my post –  Alexandre Jul 18 '12 at 9:57
also see this question: center vs. centering –  matth Jul 18 '12 at 11:59
Also captions for tables are usually placed at top of the table, while captions for drawings are placed beneath. –  N3buchadnezzar Jul 18 '12 at 14:19
Here is a discussion of the caption placement –  matth Jul 21 '12 at 13:43

As stated in a comment, overuse of rules in a table is considered bad style. Perhaps you prefer this alternative design (which follows the rules and guidelines of the booktab manual):

\documentclass{article}
\usepackage{multirow}
\usepackage{booktabs}
\begin{document}
\begin{table}\label{eval_table}\centering
\begin{tabular}{cccc}
\toprule
Topology & Average Delay(s) & Average Bandwidth(kbps) & Hosts \\
\midrule
Low & 0.0994 & 2441.85 & \multirow{2}{*}{64} \\
High & 0.1424 & 2515.77 & \\