表格错误:“!额外的},或忘记了$”

表格错误:“!额外的},或忘记了$”

对于表格的第一行,出现此错误:

> ! Extra }, or forgotten $.<template> \unskip \hfil }\hskip \tabcolsep  
> \endtemplate 1 &    ! Missing $ inserted.<inserted text>$ 1 & !  
> Missing } inserted.<inserted text>} 1 & ! Extra alignment tab has been  
> changed to \cr.<recently read> \endtemplate 1 & 

这仅在添加表格的第五列后发生


\documentclass[a4paper,twocolumn,12pt]{article}
\usepackage[top=25mm,bottom=25mm,left=25mm,right=25mm]{geometry}
\usepackage{amssymb, amsmath} 
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{url}
\usepackage{setspace} 
\usepackage{gensymb}
\setstretch{1.44}
\setlength{\columnsep}{6mm}
\usepackage{titlesec}
\titleformat{\section}{\bfseries\large\scshape\filcenter}{\thesection}{1em}{}
\titleformat{\subsection}{\bfseries\normalsize\scshape\filcenter}{\thesubsection}{1em}{}
\titlespacing{\section}{0pt}{2pt}{0pt}
\titlespacing{\subsection}{0pt}{2pt}{0pt}
% Following change makes the caption size footnotesize From: http://rorasa.wordpress.com/2010/01/13/instant-latex-command-for-small-figure-and-table-caption/  

\renewcommand{\abstractname}{}    % clear the title
\newcommand{\captionfonts}{\footnotesize}
\renewcommand\thesection{\Roman{section}.}
\renewcommand\thesubsection{\Alph{subsection}.}

\makeatletter
\long\def\@makecaption#1#2{
  \vskip\abovecaptionskip
   \sbox\@tempboxa{{\captionfonts #1: #2}}%
  \ifdim \wd\@tempboxa >\hsize
{\captionfonts #1: #2\par}
  \else
\hbox to\hsize{\hfil\box\@tempboxa\hfil}%
  \fi
  \vskip\belowcaptionskip}

\renewcommand\p@subsection{\thesection}
\makeatother
\begin{document}

\begin{table*}
\centering
\begin{tabular}{ccccc}
Peak No. & 2$\theta (\degree)$ & d-spacing (\AA)   & hkl values & Relative 
Intensity ($%$)\\
1        & 23.38               & 3.804$\pm$0.003   & [1~0~1] & $\sim 10$ \\
2        & 26.65               & 3.345$\pm$0.004   & [0~0~6] & $\sim 5$ \\
3        & 32.11               & 2.7872$\pm$0.0004 & [1~0~5] & $\sim 90$ \\
4        & 32.71               & 2.7380$\pm$0.0003 & [1~1~0] & $\sim 100$ \\
5        & 42.66               & 2.1196$\pm$0.0005 & [1~1~6] & $\sim 20$  \\
6        & 45.17               & 2.0072$\pm$0.0009 & [0~0~10] & $\sim 10$  \\
7        & 46.93               & 1.9362$\pm$0.0002 & [2~0~0] & $\sim 40$  \\
8        & 56.86               & 1.6194$\pm$0.0008 & [1~1~10] & $\sim 5$  \\
9        & 58.01               & 1.5899$\pm$0.0004 & [2~1~5] & $\sim 30$  \\
10       & 67.15               & 1.3940$\pm$0.0005 & [2~0~10] & $\sim 10$  \\
11       & 68.53               & 1.3693$\pm$0.0004 & [2~2~0] & $\sim 10$
\end{tabular}
\caption{Bragg angles, $2\theta$ and their respective d-spacings}
\label{xrpd}
\end{table*}

\end{document}

答案1

如何管理您的错误,我在评论中描述了这一点。在这里我想展示如何编写您的表格:

在此处输入图片描述

  • 添加包siunitx以更简洁地设置第三个表的列
  • 添加 booktabs水平规则包(您位于人们的对立面,所有行都用 分隔\hline,您没有人 :-) )

\documentclass[a4paper,twocolumn,12pt]{article}
\usepackage[top=25mm,bottom=25mm,left=25mm,right=25mm]{geometry}
\usepackage{amssymb, amsmath}
\usepackage{gensymb}
\usepackage{setspace}
\setstretch{1.44}
%\setlength{\columnsep}{6mm}


\usepackage{siunitx}
\usepackage{booktabs, makecell}

\begin{document}

\begin{table*}
\centering
\begin{tabular}{cc
                S[table-format=1.4(1),
                  separate-uncertainty = true,
                  table-align-uncertainty=false]
                c
                >{$\sim} c <{$}}
    \toprule
Peak No. & $2\theta(\degree)$ & {d-spacing (\AA)}   & hkl values &
                \multicolumn{1}{c}{\makecell[b]{Relative\\ Intensity ($\%$)}}   \\
    \midrule
1        & 23.38               & 3.804(3)           & [1 0 1]    &  10          \\
2        & 26.65               & 3.345(4)           & [0 0 6]    &  5           \\
3        & 32.11               & 2.7872(4)          & [1 0 5]    &  90          \\
4        & 32.71               & 2.7380(3)          & [1 1 0]    &  100         \\
5        & 42.66               & 2.1196(5)          & [1 1 6]    &  20          \\
6        & 45.17               & 2.0072(9)          & [0 0 10]   &  10          \\
7        & 46.93               & 1.9362(2)          & [2 0 0]    &  40          \\
8        & 56.86               & 1.6194(8)          & [1 1 10]   &  5           \\
9        & 58.01               & 1.5899(4)          & [2 1 5]    &  30          \\
10       & 67.15               & 1.3940(5)          & [2 0 10]   &  10          \\
11       & 68.53               & 1.3693(4)          & [2 2 0]    &  10          \\
    \bottomrule
\end{tabular}
\caption{Bragg angles, $2\theta$ and their respective d-spacings}
\label{xrpd}
\end{table*}

\end{document}

在下面的代码中,我仅限于在序言中列出相关的包:

相关内容