3

So I'm currently on the task of setting up my first table, to use as preset for future documents. While it works, and gives the result I'd like to see (except for {\centering} not working), it does throw 20 "Misplaced \noalign" errors (Misplaced \noalign. ^^I\end{tabularx})

Here's the code:

\documentclass[a4paper,11pt]{article}
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}
    \usepackage[ngerman]{babel}
    \usepackage{marvosym}
    \usepackage{enumerate}
    \usepackage{array}
    \usepackage{tabularx}
    \usepackage{xcolor,colortbl}        

    \definecolor{Grey}{gray}{0.8}
    \definecolor{Groy}{gray}{0.9}
\begin{document}
    \begin{tabularx}{375pt}{lX*{3}{>{\sffamily}rX}X}
        \vspace{2.5pt}\noindent
        \rowcolor{Grey}\textbf{Land} && \textbf{2002} && \textbf{2001} && \textbf{1990}\\\vspace{2.5pt}\noindent
        \cellcolor{Grey}USA && 3 800 000 && 3 778 512 && 3 040 932 \\\vspace{2.5pt}\noindent
        \rowcolor{Groy} \cellcolor{Grey}VR China && 1 602 156 && 1 421 268 && 618 000\\\vspace{2.5pt}\noindent
        \cellcolor{Grey}Japan && 935 000 && 932 904 && 857 268& \\\vspace{2.5pt}\noindent
        \rowcolor{Groy} \cellcolor{Grey}Russland && 888 936 && 888 382 && {\centering}-\\\vspace{2.5pt}\noindent
        \cellcolor{Grey}Kanada && 565 000 && 564 108 && 482 028 \\\vspace{2.5pt}\noindent
        \rowcolor{Groy} \cellcolor{Grey}Frankreich && 549 245 && 545 000 && 419 219 \\\vspace{2.5pt}\noindent
        \cellcolor{Grey}Deutschland && 543 561 && 566 835 && 566 484 \\\vspace{2.5pt}\noindent
            \rowcolor{Groy} \cellcolor{Grey}Weltproduktion && 15 750 000 && 15 684 000 && 11 179 000\\\vspace{2.5pt}\noindent
    \end{tabularx}
\end{document}

This is what it gives out: enter image description here

So, before I go around using it in something I actually have to turn in, I want it to not throw those errors, or at least understand why they're there... hope you guys can help (and mybe tell me, why centering isn't working?)

2
  • Welcome to TeX.SX! \vspace and \noindent are wrong in front of \rowcolor and also after \\.
    – egreg
    Commented Jun 12, 2016 at 12:23
  • Is there any reason why you have 9 columns declared, and really use only 4 of them?
    – Bernard
    Commented Jun 12, 2016 at 12:40

2 Answers 2

1

The tokens \vspace{2.5pt}\noindent are completely out of place there.

Here's a realization with siunitx:

\documentclass[a4paper,11pt]{article}

\usepackage{array}
\usepackage{tabularx}
\usepackage[table]{xcolor} % don't load colortbl after xcolor, use the option

\usepackage{siunitx}

\definecolor{Grey}{gray}{0.8}
\definecolor{Groy}{gray}{0.9}

\begin{document}

\noindent
\begin{tabularx}{\textwidth}{
  l *{3}{X>{\sffamily}S[table-format=8.0,detect-all]}
}
  \rowcolor{Grey}
\textbf{Land}                  && {\textbf{2002}} && {\textbf{2001}} && {\textbf{1990}}\\
\cellcolor{Grey}USA            &&  3 800 000 &&  3 778 512 &&  3 040 932 \\
  \rowcolor{Groy}
\cellcolor{Grey}VR China       &&  1 602 156 &&  1 421 268 &&    618 000 \\
\cellcolor{Grey}Japan          &&    935 000 &&    932 904 &&    857 268 \\
  \rowcolor{Groy}
\cellcolor{Grey}Russland       &&    888 936 &&    888 382 &&       {--} \\
\cellcolor{Grey}Kanada         &&    565 000 &&    564 108 &&    482 028 \\
  \rowcolor{Groy}
\cellcolor{Grey}Frankreich     &&    549 245 &&    545 000 &&    419 219 \\
\cellcolor{Grey}Deutschland    &&    543 561 &&    566 835 &&    566 484 \\
  \rowcolor{Groy}
\cellcolor{Grey}Weltproduktion && 15 750 000 && 15 684 000 && 11 179 000 \\
\end{tabularx}

\end{document}

enter image description here

However, I can see no reason for using sans serif for the data.

In my opinion, the table is better at natural width; in order to try it, replace \begin{tabularx}{\textwidth} with \begin{tabular}, remove X from the specifiers and change && into &.

For the following picture I also removed \sffamily.

enter image description here

1
  • the original example has small white spaces between the rows that's most obvious in the first column. (it looks rather nice to me; maybe the op wants it. might be good to ask that question.) Commented Jun 12, 2016 at 16:44
0

I propose a slightly different layout, playing with the overhang parameter of \columncolor, still based on siunitx. tabularx is not needed. Note that, with the table option for xcolor, you don't have to load colortbl. Also, the code is simplified with the \rowcolors command.

\documentclass[a4paper,11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[ngerman]{babel}
\usepackage[table]{xcolor}
\usepackage{siunitx}%
\definecolor{Grey}{gray}{0.8}
\definecolor{Groy}{gray}{0.9}

\begin{document}

{\setlength\extrarowheight{2.5pt}\sisetup{table-format=8.0, detect-family}
  \setlength\tabcolsep{1em}}
\centering
\rowcolors{2}{Groy}{}
\begin{tabular}{ >{\columncolor{Grey}[1em][1pt]\cellcolor{Grey}}l*{3}{>{\sffamily}S}}
  \rowcolor{Grey}\textbf{Land} & {\textbf{2002}} & { \textbf{2001}} & {\textbf{1990}} \\
  USA                          & 3 800 000       & 3 778 512        & 3 040 932       \\
  VR China                     & 1 602 156       & 1 421 268        & 618 000         \\
  Japan                        & 935 000         & 932 904          & 857 268         \\
  Russland                     & 888 936         & 888 382          & {---}           \\
  Kanada                       & 565 000         & 564 108          & 482 028         \\
  Frankreich                   & 549 245         & 545 000          & 419 219         \\
  Deutschland                  & 543 561         & 566 835          & 566 484         \\
  Weltproduktion               & 15 750 000      & 15 684 000       & 11 179 000      \\
\end{tabular}
}
\end{document} 

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .