编译问题

编译问题

我在编译包含下表的文档时遇到了问题:

\begin{table}[!h]
\centering\small
\caption{Thickness measurements on the two tubes.}
\label{tab:Thickness_measurement}
    \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}lll}
        \toprule
        Tube & Avareage thickness (mm) & Standard deviation (mm) \\
        \midrule
        [89$^\circ$$_2$/12.7$^\circ$$_1$/89$^\circ$$_2$] & 2.08 & 0.034 \\
        \midrule
        [55$^\circ$$_n$] & 0.254 & 0.027 \\
        \bottomrule
    \end{tabular*}
\end{table}

我正在使用 MiKTeX,我的日志中没有收到任何错误消息或任何异常信息,我只需单击编译按钮,它就会开始工作并一直保持下去,直到我中止它。

我设法通过替换[89$^\circ$$_2$/12.7$^\circ$$_1$/89$^\circ$$_2$]一些随机文本使其工作,f如下表所示:

\begin{table}[!h]
\centering\small
\caption{Thickness measurements on the two tubes.}
\label{tab:Thickness_measurement}
    \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}lll}
        \toprule
        Tube & Avareage thickness (mm) & Standard deviation (mm) \\
        \midrule
        f & 2.08 & 0.034 \\
        \midrule
        [55$^\circ$$_n$] & 0.254 & 0.027 \\
        \bottomrule
    \end{tabular*}
\end{table}

这可能相当模糊,但有人知道可能出了什么问题吗?

答案1

您遇到的问题是由于\midrule可以采用可选参数来指示要绘制的线条的粗细。因此,LaTeX 会扫描字符串[89$^\circ$$_2$/12.7$^\circ$$_1$/89$^\circ$$_2$]以查找度量单位,并生成错误消息,因为未找到合法的度量单位(例如pt、等)。cm

我认为最简单的解决方案是在每条指令后添加一个空行\midrule,即写入

    \midrule % insert a blank line

    [89$^\circ$$_2$/12.7$^\circ$$_1$/89$^\circ$$_2$] & 2.08 & 0.034 \\
    \midrule % insert a blank line

    [55$^\circ$$_n$] & 0.254 & 0.027 \\

除了插入空白行,您还可以在后面立即插入\null\relax\midrule。(请参阅帖子\relax和有什么区别{}讨论和之间的区别\relax\null)@ChristianHupfer 在答案中已经提出了一个单独的解决方案,即交换顺序或[......]$...... $;这样,之后扫描的第一个“项目”\midrule就是$而不是\[符号,并且不会产生混淆。

以下是包含这些想法的完整 MWE:

在此处输入图片描述

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{table}[!h]
%\centering\small  %% \centering has no effect because tabular* takes up the full text block
\caption{Thickness measurements on the two tubes.}
\label{tab:Thickness_measurement}
\smallskip % probably a good idea to have a bit of space between caption and tabular
\begin{tabular*}{\textwidth}{@{} l @{\extracolsep{\fill}} ll @{}}
\toprule
Tube & Average thickness (mm) & Standard deviation (mm) \\
\midrule\relax
[89$^\circ$$_2$/12.7$^\circ$$_1$/89$^\circ$$_2$] & 2.08 & 0.034 \\
\midrule\relax
[55$^\circ$$_n$] & 0.254 & 0.027 \\
\bottomrule
\end{tabular*}
\end{table}
\end{document}

答案2

我不确定这是否是所括行的正确格式[...],但我尝试了一下;-)

\documentclass{book}

\usepackage{booktabs}
\begin{document}

\begin{table}[h]
\centering\small
\caption{Thickness measurements on the two tubes.}
\label{tab:Thickness_measurement}
    \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}lll}
        \toprule
        Tube & Average thickness (mm) & Standard deviation (mm) \\
        \midrule
        $[89^\circ_2/12.7^\circ_1/89^\circ_2]$ & 2.08 & 0.034 \\
        \midrule
        $[55^\circ_n]$ & 0.254 & 0.027 \\
        \bottomrule
    \end{tabular*}
\end{table}

\end{document}

在此处输入图片描述

更新siunitx列:

\documentclass{book}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
\begin{table}[h]
  \centering\small
  \caption{Thickness measurements on the two tubes.}
  \label{tab:Thickness_measurement}
  \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}l*{2}{S[table-number-alignment=center]}}
    \toprule
    Tube & \multicolumn{1}{c}{Average thickness (\si{\milli\meter})} & \multicolumn{1}{c}{Standard deviation (\si{\milli\meter})} \tabularnewline
    \midrule
    $[\SI{89}{\degree}_{2}/\SI{12.7}{\degree}_{1}/\SI{89}{\degree}_{2}]$ & 2.08 & 0.034 \tabularnewline
    \midrule
    $[\SI{55}{\degree}_{n}]$ & 0.254} & 0.027 \tabularnewline
    \bottomrule
  \end{tabular*}
\end{table}

\end{document}

在此处输入图片描述

相关内容