Tabularx:列不适应宽度

Tabularx:列不适应宽度

我有下表,是用tabularx环境编写的:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} 
\usepackage{geometry} 

\usepackage{fancyhdr} 
\usepackage{etoolbox} 
\usepackage{array} 
\usepackage{booktabs} 
\usepackage{graphicx}


\usepackage[section]{placeins}


\usepackage{libertinus} %font
\usepackage{libertinust1math} %mathfont
\usepackage{microtype} %improves general typographic
\usepackage{pifont} %allow special symbol like square or circle with shadows
\usepackage{bbding} %adds more symbols
\usepackage{tabularx}
\usepackage[most]{tcolorbox}
\usepackage[autostyle]{csquotes}
\usepackage{scalerel,amssymb} %allows to scale/stretch and shift objects
%\usepackage{gensymb} %Generic symbols for both text and math mode
\usepackage{cancel} %Place lines through maths formulae


\usepackage{titlesec} %allows different title styles


%----------------------------------------------------------------------------------------

\setlength{\tabcolsep}{15pt} %This command increments column spacing in tables


  
\begin{document}

\begin{table}[h]
    \caption{Performance Using Hard Decision Detection}
    \centering
    \begin{tabularx}{0.8\textwidth}{lXXXXXXX}
    \hline\hline 
    Audio Name&\multicolumn{7}{c}{Sum of Extracted Bits} \\
    \hline 
    Police & 5 & -1 & 5& 5& -7& -5& 3\\ 
    Midnight & 7 & -3 & 5& 3& -1& -3& 5\\
    News & 9 & -3 & 7& 9& -5& -1& 9\\ 
    \hline 
    \end{tabularx}
    \label{tab:hresult}
    \end{table}

\end{document}

这是我得到的输出:

在此处输入图片描述

如何才能获得一个根据0.8\textwidth我在 中设置的选项自动调整列宽的代码tabularx?如您所见,数值超出了表格的范围,超出了边距等。此外,还添加了列之间毫无意义的额外空间。有谁知道如何解决这个问题吗?

答案1

那么以下两种方法中的一种怎么样?

在此处输入图片描述

\documentclass{article} 
\usepackage{geometry}  
\usepackage{booktabs} 
\usepackage{siunitx}
  
\begin{document}

\begin{table}[h]
    \caption{Performance Using Hard Decision Detection}
    \centering
    \begin{tabular*}{0.8\textwidth}{@{\extracolsep{\fill}}lS[table-format=1] S[table-format=-1] *{2}{S[table-format=1]} *{2}{S[table-format=-1]} S[table-format=1]}
    \toprule 
    Audio Name&\multicolumn{7}{c}{Sum of Extracted Bits} \\
    \cmidrule(r){1-1} \cmidrule(l){2-8} 
    Police & 5 & -1 & 5& 5& -7& -5& 3\\ 
    Midnight & 7 & -3 & 5& 3& -1& -3& 5\\
    News & 9 & -3 & 7& 9& -5& -1& 9\\ 
    \bottomrule 
    \end{tabular*}
    \label{tab:hresult}
\end{table}

\begin{table}[h]
    \caption{Performance Using Hard Decision Detection}
    \centering
    \begin{tabular}{lS[table-format=1] S[table-format=-1] *{2}{S[table-format=1]} *{2}{S[table-format=-1]} S[table-format=1]}
    \toprule 
    Audio Name&\multicolumn{7}{c}{Sum of Extracted Bits} \\
    \cmidrule(r){1-1} \cmidrule(l){2-8} 
    Police & 5 & -1 & 5& 5& -7& -5& 3\\ 
    Midnight & 7 & -3 & 5& 3& -1& -3& 5\\
    News & 9 & -3 & 7& 9& -5& -1& 9\\ 
    \bottomrule 
    \end{tabular}
    \label{tab:hresult}
\end{table}

\end{document}

相关内容