As can be seen in my MWE below, I'm using tabularx
to create a table with alternating colors. For different reasons, I defined three new column types L
, C
and R
that shall automatically fill out the whole \textwidth
and are left, center and right-aligned.
However, this MWE constantly fails and I can't figure out a way to get it to work and also don't know what to make of the error messages:
- Misplaced \noalign. \end{tabularx}
- Extra alignment tab has been changed to \cr. \end{tabularx}
\documentclass[11pt, oneside, a4paper]{article}
\usepackage{fontspec}
\setmainfont[BoldFont=Calibri, ItalicFont=CalibriLightItalic]{Calibri Light}
% captions
\usepackage[font={color=red, small}, justification=justified, singlelinecheck=false, tableposition=top]{caption}
% colors
\usepackage[table]{xcolor}
\usepackage{colortbl}
% tables
\usepackage{float}
\floatstyle{plaintop}
\restylefloat{table}
\usepackage{xltabular}
\usepackage{tabularx}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\usepackage{array}
\newcolumntype{L}{>{\raggedright}X}
\newcolumntype{R}{>{\raggedleft}X}
\newcolumntype{C}{>{\centering}X}
\renewcommand{\arraystretch}{0.75}
\setlength\arrayrulewidth{1pt}
\setlength\tabcolsep{0pt}
\begin{document}
\begin{table}[H]
\rowcolors{1}{white}{gray!50}
\color{red}{
\begin{tabularx}{\textwidth}{C C C}
\arrayrulecolor{gray}
\hline
\textbf{Band No.} & \textbf{Spectral Range} & \textbf{Resolution} \\
\hline
1 & 0.435 & 30 \\
2 & 0.452 & 30 \\
\hline
\end{tabularx}
}
\caption{Sensor specifications Landsat 8}
\label{tab:specs_landsat8}
\end{table}
\end{document}
I can get it to work using column definitions like this:
\begin{tabularx}{\textwidth}{
>{\arraybackslash}p{0.35\textwidth}
>{\raggedright\arraybackslash}p{0.3\textwidth}
>{\arraybackslash}p{0.35\textwidth}
}
...
\arraybackslash
to your definitions ofL
,C
andR
. Plus you really shouldn't be using the[H]
specifier.\arraybackslash
in the definition solves the whole issue! Whatever this is used for (I have no clue), it works. Great, thanks!