3

I try to make a simple table with the heaser line to be red as the following example shows:

\documentclass[a4paper]{report}
\usepackage{xcolor}
\usepackage{colortbl}

\begin{document}
    \begin{table}[ht!]
        \centering
        \def\arraystretch{1.0}  
        \begin{tabular}{| c | c |}
            \hline
            \rowcolor{red}
            \multicolumn{1}{|c}{\textcolor{white}{\textbf{XMPP Extention}} & \multicolumn{1}{|c|}{\textcolor{white}{\textbf{Usage}}} \\
                XEP-0045 & Blah Blah \\
                XEP-0049 & Blah Blah \\
                XEP-0249 & Blah Blah \\
                XEP-0055 & Blah Blah \\ 
                \hline
            \end{tabular}
        \end{table}
\end{document}

Whilst I try to compile it I get the following error:

File ended while scanning use of \multicolumn.

So I wonder why I get this error.

  • 2
    The error is \begin{tabular}[| c | c |] -- it should be written as \begin{tabular}{| c | c |} -- note the braces {} instead of the square brackets [] -- you're trying to put the column definitions into the optional argument of a tabular, which is a bad idea, so there is no {} which has the real column definitions → LaTeX eats \hline in order to interpret it as column specification -- which is wrong as well – user31729 Feb 8 at 17:35
  • 1
    \multicolumn{1}{|c}{\textcolor{white}{\textbf{XMPP Extention}} should be \multicolumn{1}{|c}{\textcolor{white}{\textbf{XMPP Extention}}}. – GuM Feb 8 at 17:46
  • Also, don't load the xcolor and colortbl pages independently. For maximum mutual compatibility, execute a single instruction: \usepackage[table]{xcolor}. For more information, see p. 9 of the user guide of the xcolor package. – Mico Feb 8 at 18:22
2

The tabular environment takes an optional argument as well as a mandatory one:

\begin{tabular}[<vpos>]{<col spec>}
  % ...
\end{tabular}

You've mistakenly placed the <col spec> in the position of <vpos>. The way TeX's consumption of tokens works, it grabs \hline as the mandatory argument, and this doesn't have any of the expected c, l, r or p specifications. That's why it defaults to c.

This is probably what you're after:

\begin{tabular}{| c | c |}
  % ...
\end{tabular}

As an aside, consider using booktabs and avoid using vertical rules |.

2

In addition to using curly braces rather than square brackets to enclose the main argument of the tabular environment -- i.e., writing {| c | c |} instead of [| c | c |] -- you should

  • use a single instruction, \usepackage[table]{xcolor}, instead of loading the xcolor and colortbl packages independently;

  • rethink your approach to designing the table's layout: If you wish to create a white-on-red header row, you shouldn't mix-and-(mis)match visual metaphors by using \hline;

  • simplify the table's further by omitting all vertical bars.

Finally, I think the word in the first header cell is spelled 'Extension', not 'Extention'.

enter image description here

\documentclass[a4paper]{report}
\usepackage[table]{xcolor}
\usepackage{array} % for '\extrarowheight' macro
\begin{document}

\begin{table}[ht!]
\setlength\extrarowheight{2pt} % for a more open "look"
\centering 
    \begin{tabular}{cc}
    \rowcolor{red}
    \color{white}\textbf{XMPP Extension} & 
    \color{white}\textbf{Usage} \\
    XEP-0045 & Blah Blah \\
    XEP-0049 & Blah Blah \\
    XEP-0249 & Blah Blah \\
    XEP-0055 & Blah Blah \\ 
    \hline
    \end{tabular}
\end{table}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.