1

Original code

    \begin{table}[H]
    \begin{center}
        \begin{tabular}{c|c}
            \hline
            标签  &   含义 \\
            \hline
            [t]     &   置顶 \\
            [b]     &   置底 \\
            [p]     &   换页 \\
            [h]     &   视情况插入中段 \\
            [H]     &   强制插入中段 \\
            \hline
        \end{tabular}
    \end{center}
    \caption{图表位置调整标签}
    \label{table:location}
\end{table}

It works fine when the tabulate only have line for "[t]", but My compiler throws several errors when I put "[b]" line and more.

Missing number, treated as zero.
<to be read again> 
LaTeX
Illegal unit of measure (pt inserted).
<to be read again> 
LaTeX
Missing = inserted for \ifdim.
<to be read again> 
LaTeX
Missing number, treated as zero.
<to be read again> 
LaTeX
Illegal unit of measure (pt inserted).
<to be read again> 
LaTeX
Missing number, treated as zero.
<to be read again> 
LaTeX
Illegal unit of measure (pt inserted).
<to be read again> 
LaTeX
Missing number, treated as zero.
<to be read again> 
LaTeX
Illegal unit of measure (pt inserted).
<to be read again> 
LaTeX

Though the code works when I use $$ to cover [tag]

    \begin{table}[H]
    \begin{center}
        \begin{tabular}{c|c}
            \hline
            标签      &   含义 \\
            \hline
            $[t]$       &   置顶 \\
            $[b]$       &   置底 \\
            $[p]$       &   换页 \\
            $[h]$       &   视情况插入中段 \\
            $[H]$       &   强制插入中段 \\
            \hline
        \end{tabular}
    \end{center}
    \caption{图表位置调整标签}
    \label{table:location}
\end{table}

I still want to know what makes my previous code wrong.

2
  • 3
    Type \relax after the instances of double-backslash.
    – Mico
    Commented Nov 29, 2023 at 3:38
  • Please, don't advertise (and don't use yourself) the [H] option. It lends to bad typesetting. And, if you're writing a LaTeX manual, you should know that center isn't good inside table or figure and `\centering should be used.
    – egreg
    Commented Nov 29, 2023 at 17:59

1 Answer 1

4

LaTeX is getting tripped up because several instances of \\ are followed by (after an intervening line break) the character [. Why? The \\ macro can take an optional argument which, if found, has to be a length, e.g., [1ex]. However, in the case of your table, LateX sees [b], which isn't a length. Hence the error message "Illegal unit of measure (pt inserted)", which IMNSHO isn't particularly illuminating.

What to do? There are actually several remedies; the solution I find most appealing -- because it conveys meaning -- is to insert \relax (translate: "stop what you're doing right now, which is to look for a possible optional argument to \\, relax, and then carry on afresh") after most instances of \\.

enter image description here

% !TEX TS-program = xelatex  %% or lualatex
\documentclass{article}

\usepackage{fontspec}
\setmainfont{Noto Serif SC} % or some other suitable font

\usepackage{float} % for '[H]' position specifier
\usepackage{booktabs} % for well-spaced horizontal rules

\begin{document}
    \begin{table}[H]
    \centering
        \begin{tabular}{@{} ll @{}}
            \toprule
            标签  &   含义 \\
            \midrule \relax
            [t]     &   置顶 \\ \relax
            [b]     &   置底 \\ \relax
            [p]     &   换页 \\ \relax
            [h]     &   视情况插入中段 \\ \relax
            [H]     &   强制插入中段 \\
            \bottomrule
        \end{tabular}

    \caption{图表位置调整标签}
    \label{table:location}
\end{table}
\end{document}
4
  • The \relax after \midrule was not necessary.
    – Tom
    Commented Nov 29, 2023 at 4:03
  • 1
    Really helpful. Thank you very much.
    – Toby
    Commented Nov 29, 2023 at 4:18
  • @Tom - Actually, it is necessary. It's because \midrule, too, can take an argument encased in square brackets. E.g., \midrule[\heavyrulewidth].
    – Mico
    Commented Nov 29, 2023 at 6:38
  • 1
    @Mico Good to know, thanks!
    – Tom
    Commented Nov 29, 2023 at 15:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .