# Tabularx alignment error

I have a question with respect to the tabularx environment and the addition of new columns. Currently I have the code for a 2-column table as

[![enter image description here][1]][1]

However when I try to add additional columns, such as using the following code, I seem to get an error. The code is as follows, for example:

 \documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\newcolumntype{L}{ >{\RaggedRight}X }
\usepackage{siunitx}
\noindent
\newcolumntype{Y}{ >{\Centering}X}
\begin{tabularx}{\textwidth}{@{} l L S[table-format=1.4] @{}}
\toprule

Category  & &  {Market Index} & &   {Barclay's Event Driven}
& &    {Hedge Fund Index} \\
\midrule
Momentum & & 0 & & 0 & & 0  \\ \addlinespace

Size    & & 0 & & 0 & & 0  \\ \addlinespace

Value   & & 0 & & 0 & & 0 \\ \addlinespace

Market Index & & 0.498 & & 0 & & 0 \\ \addlinespace

\bottomrule
\end{tabularx}
\enddocument


But I end up getting an error that says "extra alignment tab has been changed to \cr". Could someone please advise me with respect to this ? If anyone else has any additional formatting tips for me, I would greatly appreciate it. Thank you.

## 1 Answer

Not sure what you want, but you declared a table with 3 columns and used 6 &, which correspond to 7 columns, as though you thought a pair of & are equired to separate columns. I can assure you 1 is enough :o). So I added one column to the declaration and here is the code and result. Fot the column heads, I suggest loading makecell, which allows for line breaks inside \thead cells and a common formatting. I would also delete the last addlinespace(unless specific requirements, as bootabs already adds some vertical paddin above \bottomrule:

\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs, ragged2e, makecell}
\renewcommand\theadfont{\normalfont\bfseries}
\newcolumntype{L}{ >{\RaggedRight}X }
\usepackage{siunitx}
\setlength\parindent{0pt}
\newcolumntype{Y}{ >{\Centering}X}

\begin{document}

\begin{tabularx}{\textwidth}{@{} lYY S[table-format=1.4] @{}}
\toprule
\thead[lc]{Category }& \thead{Market Index} & {\thead{Barclay's \\Event Driven}}
& {\thead{Hedge Fund \\Index}} \\
\midrule
Momentum & 0 & 0 & 0 \\
\addlinespace
Size & 0 & 0 & 0 \\
\addlinespace
Value & 0 & 0 & 0 \\
\addlinespace
Market Index & 0.498 & 0 & 0 \\
\bottomrule
\end{tabularx}

\end{document}


• Thank you, that does the job quite nice. What would I have to enter in the code if I would like the middle column under the heading "Barclay's Event Driven" centered like the other columns ? – PutsandCalls Feb 23 '16 at 2:39
• I'll update my answer in a moment. – Bernard Feb 23 '16 at 2:45
• Please take a look at the updated answer. Actually, if the columns are to contain decimal numbers, you should use the S column type. – Bernard Feb 23 '16 at 2:57
• Using S[table-format=1.4] for the final column doesn't seem to serve a purpose; I'd use Y. And, for good measure, do replace "Barclay's" with "Barclays' "... – Mico Feb 23 '16 at 4:31
• Yes, that was just an illustration but Y works nicely, thanks – PutsandCalls Feb 23 '16 at 4:50