TransWikia.com

Missing # inserted in tabular mode

TeX - LaTeX Asked by Pedro Baptista on January 1, 2021

I’m somewhat new to Latex. Right now, I’m stuck with table creation. After searching this and other forums, I didn’t manage to sort this out yet, so I kindly ask for your support. If I missed the answer to thins on some other thread, please apologize me in advance.

Below you’ll find my document’s preamble and the table in question. I tried many approaches both on the table coding and the preamble, but none seemed to work. This code returns the following error:

Missing # inserted in alignment preamble.
to be read again
& l.127 …in{tabularx}{| C{4cm} | C{2cm} | C{2cm} |}
There should be exactly one # between &’s, and an halign or valign is being set up. In this case you had none, so I’ve put one in; maybe this will work.

Looking forward to your support, with kind regards,

documentclass[portuguese,a4paper, 10pt,twoside,fleqn]{article}

usepackage[utf8]{inputenc}
%usepackage[english]{babel,varioref}

usepackage[nottoc]{tocbibind}

usepackage{amsfonts,amsmath,amssymb,amsthm}
usepackage[cdot,squaren]{SIunits}
usepackage{color}
usepackage{emptypage} 
usepackage{fancyhdr}
PassOptionsToPackage{hyphens}{url}usepackage[hidelinks]{hyperref}
usepackage{icomma}
usepackage{setspace}
usepackage{subfig,graphicx}
%usepackage{tweaklist}
usepackage[english,portuges]{babel,varioref}
%usepackage{indentfirst} 
usepackage{fancyhdr}
%usepackage[normalmargins,normalleading]{savetrees}
usepackage{enumitem}
usepackage{cite}
usepackage{multicol,multirow,lipsum}
usepackage[final]{pdfpages}
usepackage[toc,page,header]{appendix}
usepackage{csquotes}
usepackage[official]{eurosym}
usepackage{array}
usepackage{hhline}
usepackage{lipsum}
usepackage{outlines}
usepackage{units}
usepackage[font=small,labelfont=bf]{caption}

usepackage{ftnxtra}
%usepackage{fnpos}
usepackage{stfloats}

usepackage{graphicx}
usepackage{subfig}

usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
%usepackage{imakeidx}
%makeindex[columns=3, title=Índice Alfabético]

usepackage{indentfirst} 

usepackage{pgfplots}
pgfplotsset{width=10cm,compat=1.9}

addtolength{oddsidemargin}{-1cm}
addtolength{evensidemargin}{-1.5cm}
addtolength{textwidth}{3.cm}
addtolength{topmargin}{-1.5cm}
addtolength{textheight}{3.cm}
setlength{headheight}{15pt}
setlength{parskip}{5pt}
newcolumntype{C}[1]{>{centeringletnewlinearraybackslashhspace{0pt}}m{#1}}

DeclareCaptionFormat{cont}{#1 textit{textbf{(continuação)}}#2#3par}

% Comentários footnote sem númeração

newcommandblfootnote[1]{%
  begingroup
  renewcommandthefootnote{}footnote{#1}%
  addtocounter{footnote}{-1}%
  endgroup
}

begin{document}
%maketitle

input{RDM2021_Trab1_Cover}

%newpage

%Índice
pagenumbering{roman}
tableofcontents
cleardoublepage

% % % % % % % % % % % % % % % % % % % % % % % % % % %
%newpage

pagenumbering{arabic}

begin{table}[h!]
centering
%begin{tabular}{C C C}
begin{tabular}{| C{4cm} | C{2cm} | C{2cm} |}
hline textbf{Gás de Efeito de Estufa} & textbf{Fórmula} & textbf{GWP a 100 anos}
hline textit{Dióxido de carbono} & $CO_2$ & 1 
hline textit{Metano} & $CH_4$ & 25 
hline textit{Óxido Nitroso} & $N_2O$ & 298 
hline textit{Hexafluoreto de Enxofre} & $SF_6$ & 22.800 
hline textit{Trifluormetano} & $CHF_3$ & 14.800 
hline textit{Difluormetano} & $CH_2F_2$ & 675 
hline textit{Tetrafluormetano} & $CF_4$ & 7.390 
hline textit{Hexafluoretano} & $C_2F_6$ & 12.200 
hline textit{Octafluorpropano} & $C_3F_8$ & 8.830 
hline textit{Perfluorbutano} & $C_4F_{10}$ & 8.860 
hline textit{Octafluorciclobutano} & $C_4F_8$ & 10.300 
hline textit{Perfluorpentano} & $C_5F_{12}$ & 13.300 
hline textit{Perfluorhexano} & $C_6F_{14}$ & 9.300 
hline textit{Black Carbon} & - & 900 
hline
end{tabular}   
caption{Valores de $CO_{2-eq}$ para alguns GHG. cite{ref:CO2eq}}
label{Tab:CO2-eq}
end{table}

end{document}

One Answer

The very same error message you get with your document can also be reproduced with the following a lot more minimal document and seems to be related to the combination of array and ftnxtra. If you wish to keep the latter package, invert the load order of the two packages and load ftnxtra before array.

documentclass{article}
usepackage{array}
usepackage{ftnxtra}

begin{document}

begin{tabular}{lll}
hline 
end{tabular}   

end{document}

While this fixes the error message and at least makes your code compilable, there are more issues with your preamble that you should address: Please make sure you only load packages you really need and if so, only load them once. Also make sure, hyperref is teh last package in your preamble (there are only a few exceptions that should be loaded after hyperref). Also, I suggest switching from SIunits with siunitx by which the former was superseeded.

Regarding the table's contents intelf: Since your second column contains chemical formulae, I would also like to encourage you to use a package dedicated from them (such as chemformula or mhchem) instead of using math mode to get the subscript numbers.

In the following MWE, I also used the before mentioned siunitx package to align the numbers in the last column and used lines from the booktabs package:

enter image description here

documentclass{article}

usepackage{ftnxtra}
usepackage{array}

usepackage{chemformula}
usepackage{siunitx}
usepackage{booktabs}

sisetup{group-separator=., group-minimum-digits=4}
begin{document}

begin{table}[h!]
centering
caption{Valores de ch{CO_{2-eq}} para alguns GHG. cite{ref:CO2eq}}
label{Tab:CO2-eq}
begin{tabular}{llS[table-format=5]}
toprule
{Gás de Efeito de Estufa} & {Fórmula} & {GWP a 100 anos}
midrule
Dióxido de carbono      & ch{CO2}   & 1 
Metano                  & ch{CH4}   & 25 
Óxido Nitroso           & ch{N2O}   & 298 
Hexafluoreto de Enxofre & ch{SF6}   & 22800 
Trifluormetano          & ch{CHF3}  & 14800 
Difluormetano           & ch{CH2F2} & 675 
Tetrafluormetano        & ch{CF4}   & 7390 
Hexafluoretano          & ch{C2F6}  & 12200 
Octafluorpropano        & ch{C3F8}  & 8830 
Perfluorbutano          & ch{C4F10} & 8860 
Octafluorciclobutano    & ch{C4F8}  & 10300 
Perfluorpentano         & ch{C5F12} & 13300 
Perfluorhexano          & ch{C6F14} & 9300 
Black Carbon            & ---        & 900 
bottomrule
end{tabular}   
end{table}

end{document} 

Correct answer by leandriis on January 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP