标题左对齐,但其余列中的条目居中

标题左对齐,但其余列中的条目居中

我想要对下面的代码给出的表进行三处编辑。

首先,我希望列标题左对齐,并且列中的其余条目居中。

其次,我想将{\centering\arraybackslash}其放在最后一列标题中。(我没有在这段代码中添加它,因为有了它,代码就不会被编译。我从其他代码中看到我需要它,newline或者tabularnewline在某个地方需要它。显然,我不知道语法。)

第三,我没有看到表格右边缘的双竖线。

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

答案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}

答案2

删除最后一p列以获得右侧的双垂直线。您正在加载makecell包,因此使用其\makecell宏将标题左对齐。此外,当您使用时arraybackslash,您可以\\在行尾使用。

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

在此处输入图片描述

相关内容