3

There are three edits that I want for the table the following code gives.

First, I want the column headers left-aligned and the remaining entries in the columns centered.

Second, I would like to put {\centering\arraybackslash} in the last column header. (I don't have it in this code because with it the code would not be compiled. I have seen from other code that I need newline or tabularnewline is needed at some place. I don't know the syntax, apparently.)

Third, I am not getting a double vertical bar along the right edge of the table.

\documentclass{amsart}
\usepackage{adjustbox}
\usepackage{mathtools}

\usepackage{makecell}
\usepackage{array}

\begin{document}

\noindent \hspace*{\fill}
\setlength\extrarowheight{2pt}
\begin{tabular}{|| >{\centering\arraybackslash}l |  >{\centering\arraybackslash}p{1.5cm} | >{\centering\arraybackslash}p{2.5cm} | >{\centering\arraybackslash}p{2cm} | >{\centering\arraybackslash}p{2cm} | p{3.5cm} ||} \hline
\multicolumn{5}{|| c ||}{\textbf{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}
3
  • The reason for not getting || was explained in your last question: you have specified that to come after the 6th column, but you only have 5 entries in each row. Commented May 11, 2015 at 13:36
  • as explained in the last question, if you use \centering\arraybackslash then you can use \\ to end the row, as now. Commented May 11, 2015 at 13:38
  • and as mentioned in comments in the last question putting \raggedright\arraybackslash in your headings will make them flush left. Commented May 11, 2015 at 13:39

2 Answers 2

1
\documentclass{amsart}
\usepackage{adjustbox}
\usepackage{mathtools}

\usepackage{makecell}
\usepackage{array}

\begin{document}


\centering
% no, use \centering \noindent \hspace*{\fill}
\setlength\extrarowheight{2pt}
%  >{\centering\arraybackslash}l you can't apply paragraph settings to a `l`
% entry which is one-line.
% you only have 5 columns not 6, so I deleted the last p{}
\begin{tabular}{||l |  >{\centering\arraybackslash}p{1.5cm} | >{\centering\arraybackslash}p{2.5cm} | >{\centering\arraybackslash}p{2cm} | >{\centering\arraybackslash}p{2cm}  ||} \hline
\multicolumn{5}{|| c ||}{\textbf{Inventory of Clocks and Frequency of Chimes}} \\ \Xhline{0.8pt}
        &
\raggedright   Number of clocks&
\raggedright   Chimes $n$ times on the $n^{\mathrm{th}}$ hour  &
\raggedright   Chimes once on the hour     &
\raggedright\arraybackslash   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}
% no use \centering\hspace{\fill}

\end{document}
1

Remove the last p column to get the double vertical lines on the right. You are loading makecell package and hence use its \makecell macro to left align the headers. Further, when you use arraybackslash, you can use \\ at the end of row.

\documentclass{amsart}
\usepackage{adjustbox}
\usepackage{mathtools}

\usepackage{makecell}
\usepackage{array}

\begin{document}

\noindent \hspace*{\fill}
\setlength\extrarowheight{2pt}
\begin{tabular}{|| c |  >{\centering\arraybackslash}p{1.5cm} | >{\centering\arraybackslash}p{2.5cm} | >{\centering\arraybackslash}p{2cm} | >{\centering\arraybackslash}p{2cm} ||} \hline
\multicolumn{5}{|| l ||}{\textbf{Inventory of Clocks and Frequency of Chimes}} \\ \Xhline{0.8pt}
        &   \makecell[|l]{Number  \\ of clocks}&   \makecell[|l]{Chimes $n$ times \\ on the $n^{\mathrm{th}}$ hour \\and here}  &   \makecell[|l]{Chimes once \\ on the hour}     &   \makecell[|l]{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}

enter image description here

4
  • Why isn't "Inventory of Clocks and Frequency of Chimes" centered in your table? How did you get vertical centering among the column headers? Is \usepackage{makecell} only loaded in the preamble to use \Xhline{0.8pt for drawing the one thicker horizontal line in the table?
    – user74973
    Commented May 11, 2015 at 15:42
  • @user74973 Because I used l column type in \multicolumn{5}{|| l ||}, as you said you want it so. It is makecell that does the vertical centering as I have used the \makecell macro.
    – user11232
    Commented May 11, 2015 at 15:49
  • I said the "column headers are to be left-aligned." Anyway, I know how to center it.
    – user74973
    Commented May 11, 2015 at 16:01
  • OK. I now see your use of \makecell in your code. It both positions the column headers horizontally - left, center, or right - and centers them vertically. Thanks.
    – user74973
    Commented May 11, 2015 at 16:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .