内容未在表格中居中

内容未在表格中居中

这是来自同时使用多行和多列

基本上,我希望桌子看起来专业且居中。

在下面的示例 1 中:表格外面有一个单词使用\begin{tabular}{lccc}

示例 2:内容不在中心。使用\begin{tabular}{lSSS}

在此处输入图片描述

我不知道还能做哪些改变来让表格看起来更好。

我的完整 MWE:

\documentclass[12pt,oneside]{book}

\usepackage[showframe]{geometry}
\usepackage{amsmath}
\usepackage{ragged2e}
\usepackage{booktabs, makecell, multirow, tabularx,
            threeparttable, tabulary}
\renewcommand\theadfont{\small\bfseries} % for bold in table using \small
\renewcommand\theadgape{}
\usepackage[svgnames, table]{xcolor}
\usepackage{siunitx} %for table spacing to second row
\usepackage{graphicx}

\usepackage[font=small,
            labelfont={bf,sf}, textfont={sf}, 
            justification=centering]{caption}

\begin{document}
\begin{table}[h!]
\centering
\sisetup{table-format=3.0, table-number-alignment=center, table-column-width=2.0cm}
 \begin{tabular}{lccc}
     \toprule
      \addlinespace[1.2ex]
     \multirow{2}{*}{\textbf{Pair Number\tnote{a}}} & \multicolumn{3}{c}{\thead{\makebox[0pt]{System Nuclear Accuracy(\%)}}}\\ 
     \cmidrule{2-4}
    &{\textbf{AA}}      & {\textbf{BB}}      & {\textbf{CC}}\\
     \midrule     
    Pair 1 (A45 \& A33) & 22.22 & 22.22 & 33.33\\
    Pair 2 (A33 \& A33) & 33.33 & 33.11 & 33.11\\
    Pair 3 (A33 \& A22) & 33.3 & 19.33 & 33.89\\
        \bottomrule
    \end{tabular}
    \end{table}


\begin{table}[h!]
\centering
\sisetup{table-format=3.0, table-number-alignment=center, table-column-width=2.0cm}
 \begin{tabular}{lSSS}
     \toprule
      \addlinespace[1.2ex]
     \multirow{2}{*}{\textbf{Pair Number\tnote{a}}} & \multicolumn{3}{c}{\thead{\makebox[0pt]{System Nuclear Accuracy(\%)}}}\\ 
     \cmidrule{2-4}
    &{\textbf{AA}}      & {\textbf{BB}}      & {\textbf{CC}}\\
     \midrule     
    Pair 1 (A45 \& A33) & 22.22 & 22.22 & 33.33\\
    Pair 2 (A33 \& A33) & 33.33 & 33.11 & 33.11\\
    Pair 3 (A33 \& A22) & 33.3 & 19.33 & 33.89\\
        \bottomrule
    \end{tabular}
    \end{table}    



\end{document}

答案1

table-format将从更正3.02.2可以解决第二个表中的水平对齐问题。(就我个人而言,我会将table-column-width其减小1.5cm为 以减少表中的空白量。)

第一个表格中的文本溢出,因为多列中的文本比三列加起来的宽度要宽。为了解决这个问题,您可以像第二个示例中那样增加列宽,或者添加换行符。

在此处输入图片描述

\documentclass[12pt,oneside]{book}

\usepackage[]{geometry}
\usepackage{amsmath}
\usepackage{ragged2e}
\usepackage{booktabs, makecell, multirow, tabularx,
            threeparttable, tabulary}
\renewcommand\theadfont{\small\bfseries} % for bold in table using \small
\renewcommand\theadgape{}
\usepackage[svgnames, table]{xcolor}
\usepackage{siunitx} %for table spacing to second row
\usepackage{graphicx}

\usepackage[font=small,
            labelfont={bf,sf}, textfont={sf}, 
            justification=centering]{caption}

\begin{document}
\begin{table}[h!]
\centering
\sisetup{table-format=2.2, table-number-alignment=center}
 \begin{tabular}{lSSS}
     \toprule
      \addlinespace[1.2ex]
     \multirow{2}{*}{\textbf{Pair Number\tnote{a}}} & \multicolumn{3}{c}{\thead{System Nuclear\\ Accuracy(\%)}}\\ 
     \cmidrule{2-4}
    &{\textbf{AA}}      & {\textbf{BB}}      & {\textbf{CC}}\\
     \midrule     
    Pair 1 (A45 \& A33) & 22.22 & 22.22 & 33.33\\
    Pair 2 (A33 \& A33) & 33.33 & 33.11 & 33.11\\
    Pair 3 (A33 \& A22) & 33.3 & 19.33 & 33.89\\
        \bottomrule
    \end{tabular}
    \end{table}


\begin{table}[h!]
\centering
\sisetup{table-format=2.2, table-number-alignment=center, table-column-width=2.0cm}
 \begin{tabular}{lSSS}
     \toprule
      \addlinespace[1.2ex]
     \multirow{2}{*}{\textbf{Pair Number\tnote{a}}} & \multicolumn{3}{c}{\thead{\makebox[0pt]{System Nuclear Accuracy(\%)}}}\\ 
     \cmidrule{2-4}
    &{\textbf{AA}}      & {\textbf{BB}}      & {\textbf{CC}}\\
     \midrule     
    Pair 1 (A45 \& A33) & 22.22 & 22.22 & 33.33\\
    Pair 2 (A33 \& A33) & 33.33 & 33.11 & 33.11\\
    Pair 3 (A33 \& A22) & 33.3 & 19.33 & 33.89\\
        \bottomrule
    \end{tabular}
    \end{table}    



\end{document}

相关内容