2

I'm dealing with the powerful tabularx environment. I was able to obtain a nice table, except for the last column. I need seven columns in total, but at the end I got another half column. I can't understand why!

Here the code I used for building the table:

\begin{table}[h!]
 \begin{tabularx}{\textwidth}{|l|*{20}{>{\arraybackslash}X|}}

\multicolumn{1}{c}{}& \multicolthead{3}{\color{RoyalBlue}\textbf{I}}& \multicolthead{3}{\color{RoyalBlue}\textbf{II}} & \multicolthead{3}{\color{RoyalBlue}\textbf{III}} & \multicolthead{3}{\color{RoyalBlue}\textbf{IV}} & \multicolthead{3}{\color{RoyalBlue}\textbf{V}} & \multicolthead{3}{\color{RoyalBlue}\textbf{VI}} \\

\hline

\thead{\color{RoyalBlue}One\\\color{RoyalBlue} Time} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} \\

\hline

\thead{\color{RoyalBlue}Two\\\color{RoyalBlue} Times} & & & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & & & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & \\

\hline

\thead{\color{RoyalBlue}Three\\\color{RoyalBlue}Times} & \multicolumn{3}{l|}{} & & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & & & \multicolumn{3}{l|}{} \\ 

\hline

\thead{\color{RoyalBlue}Four\\\color{RoyalBlue} \& Times} & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & & \\

\hline

\end{tabularx}
\caption{{Caption}}
\end{table}

Which produces the following output:

Last Column Problem

Does anyone have an idea?

1
  • You really need to be more forthcoming. What does \thead's definition look like? We really want to just copy-and-paste-and-compile an see the problem you're experiencing. At the moment this is not possible. The code you provide should start with \documentclass and end with \end{document}. See how to create a minimal working example (MWE).
    – Werner
    Commented Feb 1, 2015 at 19:58

1 Answer 1

3

For columns with vertical rules, you need to supply sufficient &s so that the cell is actually set. You're missing a last-column & to "enter" the last column, leaving the right-hand vertical rule missing.

In order to drop the seemingly ill-fated last column, you only need 18 columns, yet you've suggested 20 in your tabular preamble. Below this is corrected:

enter image description here

\documentclass{article}

\usepackage{tabularx,colortbl}
\usepackage[dvipsnames]{xcolor}
\newcommand{\thead}[1]{\begin{tabular}{@{}c@{}}#1\end{tabular}}
\newcommand{\multicolthead}[2]{\multicolumn{#1}{@{}c@{}}{\thead{#2}}}

\begin{document}

\noindent
\begin{tabularx}{\textwidth}{|l|*{18}{>{\arraybackslash}X|}}
  \multicolumn{1}{c}{}& \multicolthead{3}{\color{RoyalBlue}\textbf{I}}& \multicolthead{3}{\color{RoyalBlue}\textbf{II}} & \multicolthead{3}{\color{RoyalBlue}\textbf{III}} & \multicolthead{3}{\color{RoyalBlue}\textbf{IV}} & \multicolthead{3}{\color{RoyalBlue}\textbf{V}} & \multicolthead{3}{\color{RoyalBlue}\textbf{VI}} \\
  \hline
  \thead{\color{RoyalBlue}One\\\color{RoyalBlue} Time} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} \\
  \hline
  \thead{\color{RoyalBlue}Two\\\color{RoyalBlue} Times} & & & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & & & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} \\
  \hline
  \thead{\color{RoyalBlue}Three\\\color{RoyalBlue}Times} & \multicolumn{3}{l|}{} & & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & & & \multicolumn{3}{l|}{} \\ 
  \hline
  \thead{\color{RoyalBlue}Four\\\color{RoyalBlue} \& Times} & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & & \\
  \hline
\end{tabularx}

\end{document}
3
  • Thank you for answering me! You're right about the MWE, sorry if I didn't write it. Your code works very well, but probably I didn't explain well what doesn't work in my table. Actually, the borders of the last column are not the problem. The problem is really the last column: I don't want it! The table should finish with the column "VI". I hope now it's more clear, sorry. And, this is the definition I used for theadset and multicolthead: \renewcommand\theadset{\setstretch{}} \newcommand\multicolthead[2]{\multicolumn{#1}{c}{\thead{#2}}}
    – Dawson
    Commented Feb 1, 2015 at 20:14
  • @user51937: I've corrected the answer to reflect your request.
    – Werner
    Commented Feb 1, 2015 at 21:57
  • Oh gaush, 18 and not 20. Now I understood. Thank you very much @Werner!
    – Dawson
    Commented Feb 2, 2015 at 0:16

You must log in to answer this question.

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