繁体   English   中英

在 LaTex、Overleaf 中制作表格时如何修复额外对齐和非法字符错误

[英]How to fix an extra alignment and illegal character error when making a table in LaTex, Overleaf

我在 Latex 中创建了一个表格,但它已停止显示它,但我需要它来处理我当前正在处理的文档。 当我输入一个新文档时,它又可以工作了。 我收到以下错误:

LaTex 错误:数组 arg 中存在非法字符。 在第 70--98 行的段落中的过满 \\Hbox(56.47151pt 太宽)

错误对齐选项卡已更改为 \\cr。

当我包含数组包时,它也不起作用。 我正在使用以下软件包:

\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{url}
\usepackage[round]{natbib}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
 \usepackage{float}
 \usepackage{amsmath}
\usepackage[toc,page]{appendix}

\begin{table}[h!] 
\begin{center}
\caption{A comparison between Rwanda and The Gambia}
\begin{tabular}{l|s|r|m} 
  \textbf{Variable} & 
  \textbf{Specific Variable} & 
  \textbf{Rwanda} &
  \textbf{Gambia} &
  \hline \hline
 \textit{Size} & Surface area (sq. km) & 26,340 & 11,300 \\
  & Population (total) & 12,208,407 & 2,100,568 \\
  \hline
  \textit{Economy} & GDP growth (annual \%) & 6.1 & 4.6 \\
   & GDP per capita & 720 & 680 \\
\hline
  \textit{Education} &  Literacy rate (gender parity index) & 1.029 & 0.851 \\

  & School enrolment (primary \% gross) & 133.425 & 97.115 \\
  & School enrolment (secondary \% gross) & 32.988 & 57.096 \\
  & School enrolment (tertiary \% gross) & 6.695 & 3.094 \\
\hline
 \textit{Health and Survival} & Life expectancy at birth (total years) & 67.129 & 61.193 \\

   \hline
 \textit{Politics} & Political Elections & 4 & 8 \\
  &  Freedom Rights Score & Not Free & Not Free \\
  \hline 
 \textit{Gender Equality} & Gender equality rating & 4.5 & 3.5 \\
& The Global Gender Gap Report& 121 & 6 \\
\hline 
 \textit{Aid Rates}  &  Net ODA received per capita & 100.373 & 128.356 \\

  & Net official development assistance & 37.3 & 46.8 \\
  \end{tabular}
 \end{center}
 \end{table}

关于第一个问题,“数组 arg 中存在非法字符”,确实是由无法识别的 tabular 参数引起的。

合法参数应该描述列类型,并且是 c(居中)、l(左对齐)、r(右对齐)、p{width}(顶部对齐的段落)和 | 描述最常见的列间规则。 有些包会添加额外的列类型,但在您的代码中\\begin{tabular}{l|s|r|m} 's' 是未知的,并且不对应于有效的列类型。 'm' 存在以在 'array' 包中指定中间对齐的段落; 它需要插入包和具有所需段落宽度的额外参数。 只需使用合法参数更改 's' 和 'm' 就可以了。 有许多文档可以描述有效的列类型。

第二条消息表示您指定了一个包含四列的数组,但第一行包含 5 个条目:

  \textbf{Variable} & 
  \textbf{Specific Variable} & 
  \textbf{Rwanda} &
  \textbf{Gambia} &

第五个是“冈比亚”之后的&符号后面的空条目。 用行尾替换它以抑制问题。

这是一个更正的版本。

\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{url}
\usepackage[round]{natbib}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
 \usepackage{float}
 \usepackage{amsmath}
\usepackage[toc,page]{appendix}

\begin{document}

\begin{table}[h!] 
\begin{center}
\caption{A comparison between Rwanda and The Gambia}
\begin{tabular}{l|c|r|c} 
  \textbf{Variable} & 
  \textbf{Specific Variable} & 
  \textbf{Rwanda} & 
  \textbf{Gambia} \\
  \hline \hline
 \textit{Size} & Surface area (sq. km) & 26,340 & 11,300 \\
  & Population (total) & 12,208,407 & 2,100,568 \\
  \hline
  \textit{Economy} & GDP growth (annual \%) & 6.1 & 4.6 \\
   & GDP per capita & 720 & 680 \\
\hline
  \textit{Education} &  Literacy rate (gender parity index) & 1.029 & 0.851 \\

  & School enrolment (primary \% gross) & 133.425 & 97.115 \\
  & School enrolment (secondary \% gross) & 32.988 & 57.096 \\
  & School enrolment (tertiary \% gross) & 6.695 & 3.094 \\
\hline
 \textit{Health and Survival} & Life expectancy at birth (total years) & 67.129 & 61.193 \\

   \hline
 \textit{Politics} & Political Elections & 4 & 8 \\
  &  Freedom Rights Score & Not Free & Not Free \\
  \hline 
 \textit{Gender Equality} & Gender equality rating & 4.5 & 3.5 \\
& The Global Gender Gap Report& 121 & 6 \\
\hline 
 \textit{Aid Rates}  &  Net ODA received per capita & 100.373 & 128.356 \\

  & Net official development assistance & 37.3 & 46.8 \\
  \end{tabular}
 \end{center}
\end{table}
\end{document}

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM