简体   繁体   中英

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

I have created a table in Latex and it has stopped displaying it but I need it to work on the document I am currently working on. When I input into a new document, it works again. I am getting the following errors:

LaTex error: Illegal character in array arg. Overfull \\Hbox (56.47151pt too wide) in paragraph at lines at lines 70--98

Error alignment tab has been changed to \\cr.

It does not work either when I include the array package. I am using the following packages:

\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}

Concerning the first problem, "Illegal character in array arg", it is indeed cause by by an unrecognised argument to tabular.

Legal arguments are supposed to describe column types and are c (centered), l (left aligned), r (right aligned), p{width} (top aligned paragraph) and | to describe an intercolumn rule for the most common ones. There are packages that add extra column types, but in your code \\begin{tabular}{l|s|r|m} 's' is unknown and do not correspond to a valid column type. 'm' exists to specify a middle aligned paragraph in the 'array' package; it would require the insertion of the package and an extra argument with the desired width of the paragraph. Just change 's' and 'm' wih legal parameters and all is OK. There are many documentation available that describe valid column types.

The second message says that you specify an array with four columns but the fist line contains 5 entries:

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

the fifth one is an empty entry following the ampersand after 'Gambia'. Replace it with an end-of-line to suppress the problem.

Here is a corrected version.

\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}

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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