表格的表头可以移到左边但列内容可以居中吗?

表格的表头可以移到左边但列内容可以居中吗?

我想让第一列居中。当我将 改为 时,所有的l都不再起作用。请问我该怎么做?Y\makecell{}

在此处输入图片描述

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{placeins}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\usepackage{graphicx,booktabs,mhchem,makecell,array}
\usepackage{comment}
\usepackage{amsmath}
\usepackage{multirow}

\begin{document}

\begin{table}[]
    \centering
    
    \begin{tabularx}{\textwidth}{@{}lYYYYYYYYY@{}}
    
    \toprule

    \textbf{\makecell{Region type\textbackslash \\IC per Car}} &  \textbf{IC1-0C} &  \textbf{IC1-1C} &  \textbf{IC1-2C} &  \textbf{IC2-0C} &  \textbf{IC2-1C} &  \textbf{IC2-2C} &  \textbf{IC3-0C} &  \textbf{IC3-1C} &  \textbf{IC3-2C} \\
     \cmidrule(lr){2-10} 
    \textbf{R1} &  84.525 &  14.038 &   1.437 &  53.287 &  35.188 &  11.526 &   9.720 &  28.090 &   0.622 \\
    \textbf{R2} &  85.181 &  14.068 &   0.751 &  55.938 &  38.756 &   5.306 &  20.618 &  49.456 &   0.299 \\
    \textbf{R3} &  75.060 &  23.887 &   1.052 &  51.086 &  42.191 &   6.722 &  20.291 &  53.723 &   0.260 \\
    \textbf{R4} &  78.795 &  18.953 &   2.252 &  52.918 &  42.833 &   4.249 &  15.119 &  59.352 &   0.255 \\
    \textbf{R5} &  75.646 &  21.645 &   2.709 &  43.881 &  48.455 &   7.664 &  17.071 &  49.619 &   0.333 \\
    \textbf{R6} &  79.597 &  19.128 &   1.275 &  46.832 &  44.734 &   8.435 &  20.732 &  50.852 &   0.284 \\
    \textbf{R7} &  79.597 &  19.128 &   1.275 &  46.832 &  44.734 &   8.435 &  20.732 &  50.852 &   0.284 \\
    \bottomrule
    \end{tabularx}
    %\end{tabular}
    \caption{Caption}
    \label{tab:nn}
\end{table}

\end{document}

答案1

我会用粗体,没必要。第一次实现时,我使用粗体,\small这样表格就合适了。

但是,您不应该使单元格超载:第二种认识似乎更清楚地说明了哪个标题引用哪些列。

\documentclass{article}

\usepackage{booktabs,siunitx}

\begin{document}

\begin{table}[htp]
\centering
\small

% local settings
\setlength{\tabcolsep}{0pt}
\newcommand{\HH}[2][c]{%
  \begin{tabular}{@{}#1@{}}#2\end{tabular}%
}
%%
    
\begin{tabular*}{\textwidth}{
  @{\extracolsep{\fill}}
  c
  S[table-format=2.3]
  S[table-format=2.3]
  S[table-format=1.3]
  S[table-format=2.3]
  S[table-format=2.3]
  S[table-format=2.3]
  S[table-format=2.3]
  S[table-format=2.3]
  S[table-format=1.3]
  @{}
}
\toprule

\HH[l]{Region type\textbackslash \\ IC per Car} &
{\HH{IC1-\\0C}} &  {\HH{IC1-\\1C}} &  {\HH{IC1-\\2C}} &
{\HH{IC2-\\0C}} &  {\HH{IC2-\\1C}} &  {\HH{IC2-\\2C}} &
{\HH{IC3-\\0C}} &  {\HH{IC3-\\1C}} &  {\HH{IC3-\\2C}} \\
\midrule
R1 &  84.525 &  14.038 &   1.437 &  53.287 &  35.188 &  11.526 &   9.720 &  28.090 &   0.622 \\
R2 &  85.181 &  14.068 &   0.751 &  55.938 &  38.756 &   5.306 &  20.618 &  49.456 &   0.299 \\
R3 &  75.060 &  23.887 &   1.052 &  51.086 &  42.191 &   6.722 &  20.291 &  53.723 &   0.260 \\
R4 &  78.795 &  18.953 &   2.252 &  52.918 &  42.833 &   4.249 &  15.119 &  59.352 &   0.255 \\
R5 &  75.646 &  21.645 &   2.709 &  43.881 &  48.455 &   7.664 &  17.071 &  49.619 &   0.333 \\
R6 &  79.597 &  19.128 &   1.275 &  46.832 &  44.734 &   8.435 &  20.732 &  50.852 &   0.284 \\
R7 &  79.597 &  19.128 &   1.275 &  46.832 &  44.734 &   8.435 &  20.732 &  50.852 &   0.284 \\
\bottomrule
\end{tabular*}

\caption{Caption}
\label{tab:nn}
\end{table}

\begin{table}[htp]
\centering
%\small

% local settings
\setlength{\tabcolsep}{0pt}
\newcommand{\HH}[2][c]{%
  \begin{tabular}{@{}#1@{}}#2\end{tabular}%
}
%%
    
\begin{tabular*}{\textwidth}{
  @{\extracolsep{\fill}}
  c
  S[table-format=2.3]
  S[table-format=2.3]
  S[table-format=1.3]
  S[table-format=2.3]
  S[table-format=2.3]
  S[table-format=2.3]
  S[table-format=2.3]
  S[table-format=2.3]
  S[table-format=1.3]
  @{}
}
\toprule

\smash{\begin{tabular}[t]{c} Region \\ Type \end{tabular}} &
\multicolumn{9}{c}{IC per Car} \\
\cmidrule{2-10}
& {\HH{IC1-\\0C}} &  {\HH{IC1-\\1C}} &  {\HH{IC1-\\2C}}
& {\HH{IC2-\\0C}} &  {\HH{IC2-\\1C}} &  {\HH{IC2-\\2C}}
& {\HH{IC3-\\0C}} &  {\HH{IC3-\\1C}} &  {\HH{IC3-\\2C}} \\
\midrule
R1 &  84.525 &  14.038 &   1.437 &  53.287 &  35.188 &  11.526 &   9.720 &  28.090 &   0.622 \\
R2 &  85.181 &  14.068 &   0.751 &  55.938 &  38.756 &   5.306 &  20.618 &  49.456 &   0.299 \\
R3 &  75.060 &  23.887 &   1.052 &  51.086 &  42.191 &   6.722 &  20.291 &  53.723 &   0.260 \\
R4 &  78.795 &  18.953 &   2.252 &  52.918 &  42.833 &   4.249 &  15.119 &  59.352 &   0.255 \\
R5 &  75.646 &  21.645 &   2.709 &  43.881 &  48.455 &   7.664 &  17.071 &  49.619 &   0.333 \\
R6 &  79.597 &  19.128 &   1.275 &  46.832 &  44.734 &   8.435 &  20.732 &  50.852 &   0.284 \\
R7 &  79.597 &  19.128 &   1.275 &  46.832 &  44.734 &   8.435 &  20.732 &  50.852 &   0.284 \\
\bottomrule
\end{tabular*}

\caption{Caption}
\label{tab:nn-again}
\end{table}

\end{document}

在此处输入图片描述

答案2

在此处输入图片描述

这是您要找的内容吗?这里使用\makecell[t]{}代替\makecell{}\setlength\tabcolsep{4.5pt}(默认为6pt),\cmidrule(l){2-10}代替\cmidrule(lr){2-10}[来自@Mico] 和 a c(如中心)作为第一列(而不是Yl)。

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{placeins}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\usepackage{graphicx,booktabs,mhchem,makecell,array}
\usepackage{comment}
\usepackage{amsmath}
\usepackage{multirow}

\begin{document}

\begin{table}[]
    \setlength\tabcolsep{4.5pt}
    \caption{Caption}
    \label{tab:nn}
    
    \begin{tabularx}{\textwidth}{@{}cYYYYYYYYY@{}}
    \toprule
    \textbf{\makecell[t]{Region type\textbackslash \\IC per Car}} &  \textbf{IC1-0C} &  \textbf{IC1-1C} &  \textbf{IC1-2C} &  \textbf{IC2-0C} &  \textbf{IC2-1C} &  \textbf{IC2-2C} &  \textbf{IC3-0C} &  \textbf{IC3-1C} &  \textbf{IC3-2C} \\
   \cmidrule(l){2-10}
    \textbf{R1} &  84.525 &  14.038 &   1.437 &  53.287 &  35.188 &  11.526 &   9.720 &  28.090 &   0.622 \\
    \textbf{R2} &  85.181 &  14.068 &   0.751 &  55.938 &  38.756 &   5.306 &  20.618 &  49.456 &   0.299 \\
    \textbf{R3} &  75.060 &  23.887 &   1.052 &  51.086 &  42.191 &   6.722 &  20.291 &  53.723 &   0.260 \\
    \textbf{R4} &  78.795 &  18.953 &   2.252 &  52.918 &  42.833 &   4.249 &  15.119 &  59.352 &   0.255 \\
    \textbf{R5} &  75.646 &  21.645 &   2.709 &  43.881 &  48.455 &   7.664 &  17.071 &  49.619 &   0.333 \\
    \textbf{R6} &  79.597 &  19.128 &   1.275 &  46.832 &  44.734 &   8.435 &  20.732 &  50.852 &   0.284 \\
    \textbf{R7} &  79.597 &  19.128 &   1.275 &  46.832 &  44.734 &   8.435 &  20.732 &  50.852 &   0.284 \\
    \bottomrule
    \end{tabularx}
    
\end{table}
\end{document}

此外,我不知道您必须遵守哪种样式指南,但通常表格标题位于表格上方,图形标题位于下方(尽管请参考您的指南)。我改变了位置,但您可以随意将其移回。

相关内容