# Proper Formatting for Simple Tables in LaTeX

I have a table as below that doesn't format properly through pdfLaTeX. Specifically, the vertical lines for each row don't extend all the way down to create a complete box. Is there a better way to do this? The code is below.

  \begin{table}[!ht]
\fontsize{12}{12}\selectfont
\caption{Caption.}\label{label}
\center{
\begin{tabular}{|c|c|c|c|}
\hline
&a&b&c&d\\
\hline
&e&f&g&h\\
\hline
&i&j&k&l\\
\end{tabular}
}
\end{table}

• You are declaring 4 columns but inserting 5 in the table. Remove the first & at the begin of every row and it will work. For closing the "box" you also need another \hline at the end of the last row. – Nico Boni Oct 5 '14 at 16:10
• @dcmst Thanks, I completely overlooked that! – test123 Oct 5 '14 at 16:12
• In addition to fixing the issues identified by @dcmst, you should also consider using far fewer vertical and horizontal lines to begin with. Start with the vertical lines: Is there any loss of meaning if they're all deleted? If not, delete them, and let the table's cells "breathe" a bit. Next, can you make do with fewer horizontal lines? In all likelihood, the answer is yes. In general, let yourself be guided by the mantra "less is more". – Mico Oct 5 '14 at 16:14
• \fontsize{12}{12}\selectfont would set 12pt font on a 12pt baseline (ie no space between the lines and produce horrible uneven output) you should almost neve need \fontsize within a document. use \normalsize or \large or whatever. – David Carlisle Oct 5 '14 at 16:29
• \center is the internal form of \begin{center} it should not be used as a command (and does not take a {} argument, use \centering (with no {..}) – David Carlisle Oct 5 '14 at 16:30

Summarizing the comments made above, you should consider using the following code to create the sample 3 by 4 table:

\documentclass[10pt]{article}
\begin{document}
\begin{table}[!ht]
\large        %% not "\fontsize{12}{12}\selectfont"
\caption{Caption.}\label{label}
\centering    %% not "\center{...}"
\begin{tabular}{|c|c|c|c|}
\hline
a&b&c&d\\     %% no "&" at start of row
\hline
e&f&g&h\\
\hline
i&j&k&l\\
\hline        %% extra \hline at bottom of table
\end{tabular}
\end{table}
\end{document}


I trust you are working your way toward creating somewhat more exciting tables than the one above. When you do, you should aim for an open, "breathing" look -- rather than one dominated by lots and lots of little "jail cells" that imprison the data. A great place to start this quest is the user guide of the booktabs package; it provides a wonderful guide to open, interesting, and clean-looking tables.