# A table not displayed correctly

I provide two attempts at code to make a table with 4 rows and 5 columns. There are several unexpected features in the tables that are displayed. In both tabular environments, I have \begin{tabular}{|| l | l | l | l | l | l ||} \hline; so I would expect to have 5 vertical lines separating the columns. I only have two vertical lines separating a pair of adjacent columns. I have a double vertical line on the left side of the table but not on the right side. I include code like p{3cm} in each column to specify the width of each column and allow the column header to be typeset on two lines so that the table can fit within the margins. These commands are mostly ignored.

There is one modification that I would like to add to the table. Instead of the numbers in the second column and the check marks in the third, fourth, and fifth columns being displayed along the left edge of each column, I would like them to be centered. I used l because I did want the column headers to be aligned along the left edge of the columns.

\documentclass{amsart}
\usepackage{mathtools}

\usepackage{makecell}
\usepackage{boldline}
\setcellgapes{3pt}

\begin{document}
\noindent \hspace*{\fill}
\makegapedcells
\begin{tabular}{|| l p{3cm} |  l p{2.5cm} | l p{3cm} | l p{2.5cm} | l p{2cm} | l p{2cm} ||} \hline
\multicolumn{5}{|| c ||}{{\bf Inventory of Clocks and Frequency of Chimes}} \\ \Xhline{0.8pt}
& Number of clocks  &   Chimes $n$ times on the $n^{\mathrm{th}}$ hour  &   Chimes once on the hour     &   Chimes once on the half-hour \\ \hline
Type A  &   10              &   \checkmark                                               &                               &   \checkmark \\ \hline
Type B  &   5               &   \checkmark                                               &                               &   \\ \hline
Type C  &   3               &                                                   &   \checkmark                           &   \checkmark \\ \hline
\end{tabular}
\hspace{\fill}
\vskip0.25in

\noindent \hspace*{\fill}
\makegapedcells
\begin{tabular}{|| l |  l p{2.5cm} | l p{3cm} | l p{2.5cm} | l p{2cm} | l p{2cm} ||} \hline
\multicolumn{5}{|| c ||}{{\bf Inventory of Clocks and Frequency of Chimes}} \\ \Xhline{0.8pt}
& Number of clocks  &   Chimes $n$ times on the $n^{\mathrm{th}}$ hour  &   Chimes once on the hour     &   Chimes once on the half-hour \\ \hline
Type A  &   10              &   \checkmark                                               &                               &   \checkmark \\ \hline
Type B  &   5               &   \checkmark                                               &                               &   \\ \hline
Type C  &   3               &                                                   &   \checkmark                           &   \checkmark \\ \hline
\end{tabular}
\hspace{\fill}

\end{document}

• Why the {tex-core} tag? – Svend Tveskæg May 10 '15 at 23:48
• @Svend Tveskæg What tag should I use? – user74973 May 10 '15 at 23:58
• How about {tables}? – Mico May 11 '15 at 0:00
• in the text you say you have lllll 5 columns but on the code you have 12 columns specified (6 l and 6 p) but you only supply 5 cells of data so the || is never reached. – David Carlisle May 11 '15 at 0:08

You had specified 12 columns in the preamble, but only supplied 5 columns of data.

\documentclass{amsart}
\usepackage{mathtools}

\usepackage{array}

\begin{document}
\centering

\setlength\extrarowheight{2pt}
\begin{tabular}{|| p{2cm} |  p{2cm} | p{2cm} | p{2.5cm} | p{2cm} ||} \hline
\multicolumn{5}{|| c ||}{\textbf{Inventory of Clocks and Frequency of Chimes}} \\ \hline
& Number of clocks  &   Chimes $n$ times on the $n^{\mathrm{th}}$ hour  &   Chimes once on the hour     &   Chimes once on the half-hour \\ \hline
Type A  &   10              &   \checkmark                                               &                               &   \checkmark \\ \hline
Type B  &   5               &   \checkmark                                               &                               &   \\ \hline
Type C  &   3               &                                                   &   \checkmark                           &   \checkmark \\ \hline
\end{tabular}

\bigskip

\end{document}

• Yes, I see that you corrected my mistake of having too many column headings. By the way, I changed the specification for the columns to {|| l | p{1.5cm} | p{2.5cm} | p{2cm} | p{2cm} | p{2cm} ||} and the columns widths are much nicer. Thanks. How can I center the numbers in the second column and the check marks? – user74973 May 11 '15 at 0:30
• use array package and >{\centering\arraybackslash}p{2.5cm} to inject \centering into each cell – David Carlisle May 11 '15 at 0:34
• I put \usepackage{array} in the preamble. I think that you may have misunderstood what I want regarding centering. I want the column headers like "Number of clocks" to be left-aligned, but I want the numbers 10, 5, and 3 under this header to be centered. If that is your understanding, I do not know how to implement your suggesting to get the numbers centered in the column. – user74973 May 11 '15 at 0:52
• @user74973 centre the table columns and then use \raggedright in the headers (end the table row with \tabularnewline if you do that in the last column. There are 1000s of examples of table heading settings on this site. – David Carlisle May 11 '15 at 0:54
• @user74973 please stop asking new questions in comments, the site format doesn't support it. l{2.5cm} is a syntax error you will get an error message from latex, you really need to start with a basic latex tutorial rather than just randomly changing code. The code I posted answered the original question and runs without error. – David Carlisle May 11 '15 at 12:55

I would simplify and re-organize the table's structure along the following two bullet points:

• Use a tabularx environment with four equally wide data columns, and adjust the column count accordingly. Note that it is possible to have c as the column type for the body of the table along with P (a modified form of the X column type) for the header cells. The P column type allows automatic line breaking while setting its contents ragged-right, which is what I understand is what you want for the header.

• Omit all vertical lines, omit all horizontal lines in the interior of the table, and use the rule-drawing macros of the booktabs package to draw the remaining horizontal lines.

\documentclass{amsart}
\usepackage{tabularx,booktabs}
\newcolumntype{P}{>{\raggedright\arraybackslash}X}

\begin{document}
\noindent
\begin{tabularx}{\textwidth}{ l cccc }
\toprule
& \multicolumn{4}{ c }{{\bfseries Inventory of Clocks and Frequency of Chimes}} \\
\cmidrule(l){2-5}
& \multicolumn{1}{P}{Number of clocks}
& \multicolumn{1}{P}{Chimes $n$ times on the $n^{\mathrm{th}}$ hour}
& \multicolumn{1}{P}{Chimes once on the hour}
& \multicolumn{1}{P}{Chimes once on the half-hour} \\
\midrule
Type A  &   10 &   \checkmark & \checkmark & \\
Type B  &   5  &   \checkmark &  &  \\
Type C  &   3  &  &   \checkmark &   \checkmark \\
\bottomrule
\end{tabularx}

\end{document}


Addendum: Speaking for myself, I think the table's appearance could be improved further by centering the material in the header cells as well. This may be achieved by using \centering instead of \raggedright in the definition of the P column type.

\documentclass{amsart}
\usepackage{tabularx,booktabs}
\newcolumntype{P}{>{\centering\arraybackslash}X}

\begin{document}
\noindent
\begin{tabularx}{\textwidth}{@{} l cccc @{}}
\toprule
& \multicolumn{4}{ c }{{\bfseries Inventory of Clocks and Frequency of Chimes}} \\
\cmidrule(l){2-5}
& \multicolumn{1}{P}{Number of clocks}
& \multicolumn{1}{P}{Chimes $n$ times on the $n^{\mathrm{th}}$ hour}
& \multicolumn{1}{P}{Chimes once on the hour}
& \multicolumn{1}{P@{}}{Chimes once on the half-hour} \\
\midrule
Type A  &   10 &   \checkmark & \checkmark & \\
Type B  &   5  &   \checkmark &  &  \\
Type C  &   3  &  &   \checkmark &   \checkmark \\
\bottomrule
\end{tabularx}

\end{document}