我遇到了这个问题,每当我想将表格插入我的 latex 文档时,它都会给我一个错误:我不知道我做错了什么。如果有人能帮助我,我将不胜感激。我浏览了各种帖子以寻求解决方案,但无济于事。请帮助我。
我正在使用这个文档类:
\documentclass[12pt,bibtotoc,liststotoc,BCOR5mm,DIV12]{book}
我使用的软件包:
\usepackage[ngerman, english]{babel}
\usepackage{bibgerm}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage{tabulary}
\usepackage[none]{hyphenat}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{array}
\usepackage{tabu}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{url}
\usepackage{listings, color}
\usepackage{subfig}
%\usepackage{scrpage2}
\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage{float}
\usepackage{siunitx}
\usepackage{layout}
\usepackage{etoolbox}
\usepackage{titlesec}
\usepackage{parskip}
\usepackage{ftnxtra}
\usepackage{fnpos}
\usepackage[acronym,toc]{glossaries}
%\usepackage[singlespacing]{setspace}
\usepackage[
colorlinks=true
,breaklinks
,ngerman
]{hyperref}
\usepackage[hyphenbreaks]{breakurl}
\usepackage[dvipsnames]{xcolor}
\definecolor{c1}{rgb}{0,0,1}
\definecolor{c2}{rgb}{0,0.3,0.9}
\definecolor{c3}{rgb}{0.3,0,0.9}
\usepackage{cite}
\usepackage[nottoc]{tocbibind}
\usepackage{longtable}
\usepackage{bigstrut}
\usepackage{enumerate}
\usepackage{microtype}
桌子:
\begin{table}[htbp]
\centering
\begin{tabular}{|l|r|}
Acquisition Date & 06/03/1985 \\ \hline
Product & \multicolumn{1}{l}{TM L1T} \\ \hline
Quality & 9 \\ \hline Cloud Cover & 30\% \\ \hline
LMAX_Band 6 & 15.303 \\ \hline
LMIN_band 6 & 1.238 \\ \hline
QCALMAX_Band 6 & 255 \\ \hline
QCALMIN_band 6 & 1 \\ \hline
\end{tabular}%
\caption{A new table}
\label{tab:table1}%
\end{table}%
错误:
! Missing # inserted in alignment preamble.
<to be read again>
\cr
l.123 \begin{tabular}{|l|r|}
There should be exactly one # between &'s, when an
\halign or \valign is being set up. In this case you had
none, so I've put one in; maybe that will work.
! Extra alignment tab has been changed to \cr.
<template> \endtemplate
l.124 Acquisition Date &
06/03/1985 \\ \hline
You have given more \span or & marks than there were
in the preamble to the \halign or \valign now in progress.
So I'll assume that you meant to type \cr instead.
! Extra alignment tab has been changed to \cr.
<template> \endtemplate
l.125 Product &
\multicolumn{1}{l}{TM L1T} \\ \hline
You have given more \span or & marks than there were
in the preamble to the \halign or \valign now in progress.
So I'll assume that you meant to type \cr instead.
! Extra alignment tab has been changed to \cr.
<template> \endtemplate
l.126 Quality &
9 \\ \hline
You have given more \span or & marks than there were
in the preamble to the \halign or \valign now in progress.
So I'll assume that you meant to type \cr instead.
! Extra alignment tab has been changed to \cr.
<template> \endtemplate
l.127 Cloud Cover &
30\% \\ \hline
You have given more \span or & marks than there were
in the preamble to the \halign or \valign now in progress.
So I'll assume that you meant to type \cr instead.
! Extra alignment tab has been changed to \cr.
<template> \endtemplate
l.128 LMAX\_Band 6 &
15.303 \\ \hline
You have given more \span or & marks than there were
in the preamble to the \halign or \valign now in progress.
So I'll assume that you meant to type \cr instead.
! Extra alignment tab has been changed to \cr.
<template> \endtemplate
l.129 LMIN\_band 6 &
1.238 \\ \hline
You have given more \span or & marks than there were
in the preamble to the \halign or \valign now in progress.
So I'll assume that you meant to type \cr instead.
! Extra alignment tab has been changed to \cr.
<template> \endtemplate
l.130 QCALMAX\_Band 6 &
255 \\ \hline
You have given more \span or & marks than there were
in the preamble to the \halign or \valign now in progress.
So I'll assume that you meant to type \cr instead.
! Extra alignment tab has been changed to \cr.
<template> \endtemplate
l.131 QCALMIN\_band 6 &
1 \\ \hline
You have given more \span or & marks than there were
in the preamble to the \halign or \valign now in progress.
So I'll assume that you meant to type \cr instead.
答案1
经过一些修复,问题的代码就可以正常工作:
\documentclass[12pt,bibtotoc,liststotoc,BCOR5mm,DIV12]{scrbook}
\begin{document}
\begin{table}[htbp]
\centering
\begin{tabular}{|l|r|}
Acquisition Date & 06/03/1985 \\ \hline
Product & \multicolumn{1}{l|}{TM L1T} \\ \hline
Quality & 9 \\ \hline Cloud Cover & 30\,\% \\ \hline
LMAX\_Band 6 & 15.303 \\ \hline
LMIN\_band 6 & 1.238 \\ \hline
QCALMAX\_Band 6 & 255 \\ \hline
QCALMIN\_band 6 & 1 \\ \hline
\end{tabular}%
\caption{A new table}
\label{tab:table1}%
\end{table}%
\end{document}
修复:
如果的默认行为
_
是在数学模式下开始下标。因此,它会在文本模式下抛出错误。可以在文本模式下使用\textunderscore
或设置下划线\_
。第二行末尾的垂直线丢失了。
数字和单位之间的小空格
30\,\%
。
更新:
可以使用两个包tabu
和来重现此问题fntxtra
。如果其中至少一个不需要,则删除不需要的包。否则,可以尝试不同的加载顺序:
\usepackage{fntxtra}
\usepackage{tabu}
错误信息消失了,但我还没有测试或分析两个包是否按照这个顺序正常工作。
答案2
导致 (几乎无法辨认的) 错误消息的直接原因是您正在加载包ftnxtra
。除非您有充分的理由加载此包 - 例如,您的文档主要以波斯语排版吗? - 您不应该加载此包。
scrbook
序言中还有第二个错误:如果您实际使用的是而不是book
文档类,那么您也不应该加载该scrpage2
包,这似乎是您发布的其他一些评论所表明的情况。
您确实应该重新审视您加载的许多软件包的必要性。此外,没有理由多次加载一个软件包。顺便问一句,您真的想全局关闭连字符吗?为什么?!
最后,如果您需要排版下划线字符,则应写\_
,而不是_
。 (您可能在某个时候了解到,这_
是 TeX 的“特殊”字符,它用于在数学模式下启动下标。) Heiko 之前的回答也提到了这一点。