Latex:表格宽度大于文本,其标签编号从 2 开始

Latex:表格宽度大于文本,其标签编号从 2 开始

我有一个用 Latex 构建的表格,它显示的尺寸大于文本的宽度。虽然我尝试了许多在线解决方案,但没有一个能解决问题。我认为这是因为标题单元格(第一行)中的文本不能被拆分,它们写在一行中。甚至它的标签也是从 2 开始而不是从 1 开始,例如, 表 2.: 标签代替表格1。 : 标签。

以下是我正在使用的代码及其输出:

\documentclass{article}
\usepackage[utf8]{inputenc}

\begin{document}

\begin{table}
\centering
\refstepcounter{table}
\caption{Example}
\begin{tabular}{lllllll}
\hline
\textbf{No} & \textbf{One-text} & \textbf{One-text} & \textbf{One-or-text}  (4,3,4)& \textbf{one-or-text}  (8,4,2)& \textbf{One-or-text}   (4,3,2)& One-or-text (4,2,2)\\ \hline
1-          & 0.0028            & 0                 & 0                    & 0                    & 0                    & 0           \\
2-          & 0.0063            & 0                 & 0.0025               & 0.00018              & 0.0000893            & 0           \\ \hline
\end{tabular}
\end{table}

 
\end{document}

在此处输入图片描述

答案1

  • 要解决编号问题,请省略指令\refstepcounter{table}

  • 正如你(重新)发现的那样,l列类型确实不是允许自动换行。为了允许在 6 个数据列中自动换行,同时将表格的整体宽度设置为\textwidth,我建议您使用tabularx环境,如下面的代码所示。

在此处输入图片描述

\documentclass{article}
\usepackage{tabularx,ragged2e}
\newcolumntype{L}{>{\RaggedRight\hspace{0pt}}X} 
    % allow line breaking, suppress full justfication

\begin{document}
\begin{table}
%%\centering % <-- not needed
%%%%\refstepcounter{table} %<-- delete or comment out this instruction
\caption{Example}
\begin{tabularx}{\textwidth}{@{} l *{6}{L} @{}}
\hline
\textbf{No} & \textbf{One-text} & \textbf{One-text} & \textbf{One-or-text} (4,3,4) & \textbf{one-or-text} (8,4,2) & \textbf{One-or-text} (4,3,2) & One-or-text (4,2,2)\\ 
\hline
1- & 0.0028 & 0 & 0      & 0       &           0 & 0 \\
2- & 0.0063 & 0 & 0.0025 & 0.00018 & 0.0000893   & 0 \\ 
\hline
\end{tabularx}
\end{table}
\end{document}

相关内容