![表格格式错误额外的对齐标签](https://linux22.com/image/291546/%E8%A1%A8%E6%A0%BC%E6%A0%BC%E5%BC%8F%E9%94%99%E8%AF%AF%E9%A2%9D%E5%A4%96%E7%9A%84%E5%AF%B9%E9%BD%90%E6%A0%87%E7%AD%BE.png)
\begin{table}{ht}
\begin{tabular}{|cc|}
\hline
10g & Tryptone //
5g & Yeast extract //
5g & NaCl //
10g & Agar //
1ml & Ampicllin (100ng/ml) /hline
\end{tabular}
\caption{Reagents for Lysogeny broth agar}
\label{table:LBAreagents}
\end{table}
我不断收到错误消息,我无论如何也找不到问题所在,据说错误发生在酵母和琼脂代码行中,代码如下
Extra alignment tab has been changed to \cr.
<recently read> \endtemplate
l.164 5g &
Yeast //
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.
<recently read> \endtemplate
l.166 10g &
Agar //
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.
[10]"
任何帮助都将非常感激。
nb 序言
\documentclass[12pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage{mathptmx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{color}
\usepackage{multirow}
\usepackage{soul}
\usepackage{caption}
\usepackage{natbib}
\usepackage{setspace}
\usepackage{placeins}
\usepackage[nottoc,numbib]{tocbibind}
\renewcommand{\bibname}{References}
\doublespacing
\usepackage[parfill]{parskip}
答案1
像这样?
我把 改为{ht}
,[ht]
然后 替换为//
,并 在最后一个之前\\
添加了一个额外的\\
\hline
\begin{table}[ht]
\begin{tabular}{|cc|}
\hline
10g & Tryptone \\
5g & Yeast extract \\
5g & NaCl \\
10g & Agar \\
1ml & Ampicllin (100ng/ml) \\
\hline
\end{tabular}
\caption{Reagents for Lysogeny broth agar}
\label{table:LBAreagents}
\end{table}
我还擅自更新了表格,并向您介绍了siunitx
显示 SI 单位数字的包、mhchem
化学式包和booktabs
用于更美观的表格格式的包。但这当然是我的偏好 :)
\documentclass[12pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage{mathptmx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{color}
\usepackage{multirow}
\usepackage{soul}
\usepackage{caption}
\usepackage{natbib}
\usepackage{setspace}
\usepackage{placeins}
\usepackage[nottoc,numbib]{tocbibind}
\renewcommand{\bibname}{References}
\doublespacing
\usepackage[parfill]{parskip}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage[version=3]{mhchem}
\begin{document}
\begin{table}[ht]
\centering
\caption{Reagents for Lysogeny broth agar}
\label{table:LBAreagents}
\begin{tabular}{cc}
\toprule
Quantities & Ingredient \\
\midrule
\SI{10}{\gram} & Tryptone \\
\SI{5}{\gram} & Yeast extract \\
\SI{5}{\gram} & \ce{NaCl} \\
\SI{10}{\gram} & Agar \\
\SI{1}{\milli\litre} & Ampicllin (\SI{100}{\nano\gram\per\milli\litre)} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
会给出类似这样的结果
答案2
以下是我使用功能强大的siunitx
包裹:
\documentclass{report}
\usepackage[tableposition = top]{caption} % table caption position
\usepackage{booktabs} % horizontal lines in table
\usepackage{siunitx} % typesetting and aligning physical quantities
\usepackage[version = 4]{mhchem} % format names of chemical components
\begin{document}
\begin{table}
\centering
\caption{Reagents for Lysogeny broth agar.}
\label{table:LBAreagents}
\begin{tabular}{
S[table-format = 2] @{\,}
s[table-unit-alignment = left]
l
}
\toprule
10 & \g & Tryptone \\
5 & \g & Yeast extract \\
5 & \g & \ce{NaCl} \\
10 & \g & Agar \\
1 & \ml & Ampicllin (\SI[per-mode = symbol]{100}{\ng\per\ml}) \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
注意前两列的物理量和单位是垂直对齐的。这是“正确”的做法。