6

I was trying to make this table but it has blank spaces and I don't know why? Can someone tell me how to fix this?

enter image description here

This is my code:

\documentclass{article}
\begin{document}
\renewcommand{\arraystretch}{1.3}
\small
\begin{table}[ht]
\begin{tabular}{|c|c|c|c|c|}
\hline
& \multicolumn{4}{|c|}{Display Format}& \\ \cline{2-5}
&\multicolumn{2}{|c|}{High information density}& \multicolumn{2}{|c|}{Low information density} &\\ \hline
Cookie type & Noticeable& Non-noticeable& Noticeable& Non-noticeable\\ \hline
1\textsuperscript{st} &Group 1&Group 2& Group 3&Group 4\\ \hline
1\textsuperscript{st}/3\textsuperscript{rd}&Group 5& Group 6&Group 7&Group 8\\ \hline
\end{tabular}
\caption{Number of respondents per treatment}
\label{table:1}
\end{table}
\end{document}
2
  • Get rid of the \\ after {Display Format}& and {Low information density} &
    – CarLaTeX
    Commented Aug 13, 2016 at 6:40
  • if @Lana would correctly use received answer on his/her question tex.stackexchange.com/questions/324604/… or even accept better answer among received as she/he was, than this question should be unnecessary ...
    – Zarko
    Commented Aug 13, 2016 at 11:31

2 Answers 2

5

The first and second row has an additional &. TeX throws an error message and makes a new row as error recovery:

! Extra alignment tab has been changed to \cr.
<template> \endtemplate

l.9 & \multicolumn{4}{|c|}{Display Format}&
                                             \\ \cline{2-5}

Fixed example including Mico's fix:

\documentclass{article}
\begin{document}
\renewcommand{\arraystretch}{1.3}
\small
\begin{table}[ht]
  \begin{tabular}{|c|c|c|c|c|}
    \hline
    & \multicolumn{4}{c|}{Display Format}\\ \cline{2-5}
    & \multicolumn{2}{c|}{High information density}& \multicolumn{2}{c|}{Low information density}\\ \hline
    Cookie type & Noticeable& Non-noticeable& Noticeable& Non-noticeable\\ \hline
    1\textsuperscript{st} &Group 1&Group 2& Group 3&Group 4\\ \hline
    1\textsuperscript{st}/3\textsuperscript{rd}&Group 5& Group 6&Group 7&Group 8\\ \hline
  \end{tabular}
  \caption{Number of respondents per treatment}
  \label{table:1}
\end{table}
\end{document}

Result

BTW, \small is set outside of the table environment. Thus it does not change the font size inside, because floating environments usually reset the font at the beginning.

\documentclass{article}
\begin{document}
\begin{table}[ht]
  \small
  \begin{tabular}{|c|c|c|c|c|}
    \hline
    & \multicolumn{4}{c|}{Display Format} \\ \cline{2-5}
    & \multicolumn{2}{c|}{High information density}& \multicolumn{2}{c|}{Low information density}\\ \hline
    Cookie type & Noticeable& Non-noticeable& Noticeable& Non-noticeable\\ \hline
    1\textsuperscript{st} &Group 1&Group 2& Group 3&Group 4\\ \hline
    1\textsuperscript{st}/3\textsuperscript{rd}&Group 5& Group 6&Group 7&Group 8\\ \hline
  \end{tabular}
  \caption{Number of respondents per treatment}
  \label{table:1}
\end{table}
\end{document}

Result with \small

Finally a version with package booktabs, less and better lines and spacing:

\documentclass{article}
\usepackage{booktabs}
\usepackage{caption}
\usepackage[normal]{engord}% no option or option "raise" for raised suffixes

\begin{document}
\begin{table}[ht]
  \caption{Number of respondents per treatment}
  \label{table:1}
  \begin{tabular}{ccccc}
    \toprule
    & \multicolumn{4}{c}{Display Format}\\
    \cmidrule(lr){2-5}
    & \multicolumn{2}{c}{High information density} &
    \multicolumn{2}{c}{Low information density}\\
    \cmidrule(lr){2-3}
    \cmidrule(lr){4-5}
    Cookie type & Noticeable & Non-noticeable &
    Noticeable & Non-noticeable\\
    \midrule
    \engordnumber{1} & Group 1 & Group 2 & Group 3 & Group 4\\
    \engordnumber{1}/\engordnumber{3} &
    Group 5 & Group 6 & Group 7 & Group 8\\
    \bottomrule
  \end{tabular}
\end{table}
\end{document}

Result with booktabs

1
  • +1. Incidentally, all three instances of |c| in the second argument of the \multicolumn directives should be replaced with c| in order to avoid getting double-thickness vertical line segments. (The OP's screenshot suggests that the array package is being loaded, either directly or indirectly.)
    – Mico
    Commented Aug 13, 2016 at 6:47
2

By using the c column type for the four data columns, one ends up with noticeably different widths for these columns. IMHO, this makes for a less-than-optimal "look". I would like to suggest, therefore, that you use a column type that assures that the four data columns are all equally wide. One such column type is the X type, provided by the tabularx package.

I would further like to suggest that you (a) give the table a more "open" appearance -- mostly by omitting all vertical lines and by using the macros \toprule, \midrule, \bottomrule and \cmidrule, provided by the booktabs package instead of \hline and \cline -- and (b) provide more visual structure to the three-row header in order to help the reader take in the information more easily.

enter image description here

\documentclass{article}
\usepackage{booktabs,tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X} % centered "X" columns
\begin{document}

\begin{table}
\setlength\tabcolsep{3pt} % default value: 6pt
\begin{tabularx}{\textwidth}{@{}lCCCC@{}}
\toprule
Cookie type & \multicolumn{4}{c@{}}{Display Format} \\ 
\cmidrule(l){2-5}
&\multicolumn{2}{c}{High information density}
&\multicolumn{2}{c@{}}{Low information density} \\ 
\cmidrule(lr){2-3} \cmidrule(l){4-5}
& Noticeable& Non-noticeable& Noticeable& Non-noticeable\\ 
\midrule
1\textsuperscript{st} &Group 1&Group 2& Group 3&Group 4\\
1\textsuperscript{st}/3\textsuperscript{rd}&Group 5& Group 6&Group 7&Group 8\\ 
\bottomrule
\end{tabularx}
\caption{Number of respondents per treatment}
\label{table:1}
\end{table}

\end{document}

You must log in to answer this question.

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