0

I get a problem with the following table:

\begin{table}[H]  
    \newcommand{\ctab}{\centering\arraybackslash}  
    \definecolor{F1}{RGB}{255,255,255}  
    \definecolor{F0}{RGB}{210,0,0}  
    \definecolor{F2}{RGB}{0,176,80}  
    \resizebox{0.85\textwidth}{!}{\begin{tabular}{|c|c|c|c|c|c|}  
            \hline   
            \rule{0pt}{30pt}  
            \multicolumn{2}{|c|}{\cellcolor{gray!50}\huge{\textbf{a}}} &
            %\cellcolor{gray!50}\huge{\textbf{a}} &  
            %\cellcolor{gray!50}\huge{\textbf{}} &
            \cellcolor{gray!50}\huge{\textbf{b}} &  
            \cellcolor{gray!50}\huge{\textbf{C}} &  
            \cellcolor{gray!50}\huge{$\mathbf{d}$} &  
            \cellcolor{gray!50}\huge{$\mathbf{e}$}    
            \\   
            \end{tabular}}  
    \caption{XY}  
    \label{tab:XY}  
\end{table}  

Problems are with the multicolumn. If I change to:

%\multicolumn{2}{|c|}{\cellcolor{gray!50}\huge{\textbf{a}}} &  
            \cellcolor{gray!50}\huge{\textbf{a}} &  
            \cellcolor{gray!50}\huge{\textbf{}} &   

It does work...

Where is the Problem?

Thanks!

  • Please note, that your question does not show a minimal working example. For an explanation on MWE take a look here. – Skillmon Jun 30 '17 at 8:56
  • Also note, that I don't think that \huge is necessary to highlight the top row (it's coloured already). Also I personally dislike vertical lines in tables (and know several other people who share my opinion on that). You might take a look at the booktabs package for prettier horizontal rules (but they tend to break the vertical rules and \rowcolor/\cellcolor). – Skillmon Jun 30 '17 at 9:05
1

The problem is caused by your \rule in conjunction with \multicolumn because it is in the same cell as the \multicolumn. If you want to keep it, place it in another cell or inside the \multicolumn. If you just want decent spacing you might insert a \strut just after \huge.

Using \rule:

\documentclass[]{article}

\usepackage[table]{xcolor}

\begin{document}

\begin{table}
    \begin{tabular}{|c|c|c|c|c|c|}  
            \hline   
            \multicolumn{2}{|c|}{\cellcolor{gray!50}\huge{\textbf{a}}{\rule{0pt}{30pt}}} &
            \cellcolor{gray!50}\huge{\textbf{b}} &  
            \cellcolor{gray!50}\huge{\textbf{C}} &  
            \cellcolor{gray!50}\huge{$\mathbf{d}$} &  
            \cellcolor{gray!50}\huge{$\mathbf{e}$}    
            \\
            \hline
            f&g&h&i&j&k\\
            \hline
            \end{tabular}
    \caption{XY}  
    \label{tab:XY}  
\end{table} 
\end{document}

produces: enter image description here

Using \strut:

\documentclass[]{article}

\usepackage[table]{xcolor}

\begin{document}

\begin{table}
    \centering%
    \begin{tabular}{|c|c|c|c|c|c|}  
            \hline   
            \multicolumn{2}{|c|}{\cellcolor{gray!50}\huge\strut{\textbf{a}}} &
            \cellcolor{gray!50}\huge{\textbf{b}} &  
            \cellcolor{gray!50}\huge{\textbf{C}} &  
            \cellcolor{gray!50}\huge{$\mathbf{d}$} &  
            \cellcolor{gray!50}\huge{$\mathbf{e}$}    
            \\   
            \hline
            f&g&h&i&j&k\\
            \hline
            \end{tabular}
    \caption{XY}  
    \label{tab:XY}  
\end{table} 
\end{document}

produces: enter image description here

  • The\extrarowheight length is done for padding. Another solution is the cellspace package. – Bernard Jun 30 '17 at 8:50
  • @Bernard didn't know that length. But I like the look of the \strut-solution, the spacing seems just right to me. You might add an answer showing the two solutions you suggest (and take my upvote :P) – Skillmon Jun 30 '17 at 8:53
  • I didn't say it was a bad spacing! I think it's not in the spirit of LaTeX to fiddle with individual cells, and in general formatting commands within the body of the document should be avoided. Of course this remark does not take into account particular situations. – Bernard Jun 30 '17 at 8:59
  • @Bernard the fiddle with individual cells is just used because of the \huge. I don't think that the \huge in the head row is good practise but with a \huge\strut it gets correct spacing. Is \extrarowheight just applicable to the whole table (I haven't tested)? – Skillmon Jun 30 '17 at 9:02
  • Yes, it applies to all rows, but as padding is very tight in the default settings of LaTeX, that's no problem. More interesting is cellspace, which defines minimal vertical spacings at the top and bottom of cells. – Bernard Jun 30 '17 at 9:08
1

You can use \extrarowheight to add some padding at the top of all cells (it's hardly a luxury, considering the tightness of default row heights), or define a minimal vertical spacing at the top and bottom of cells in columns prefixed with the letter S.

I simplified the code using the \rowcolor command, and defining a \myhead command which comprises the font changes. I took the liberty to change the colour of the first row to a nicer shade of gray:

\documentclass[]{article}

\usepackage{ cellspace}
\usepackage[table, svgnames]{xcolor}
\setlength{\cellspacetoplimit}{4pt}
\setlength{\cellspacebottomlimit}{3pt}
\newcommand{\myhead}[1]{\huge\boldmath\bfseries#1}
\begin{document}

\begin{table}[!htb]
\centering
    \begin{tabular}{|*{6}{Sc|}}
            \hline
       \rowcolor{GhostWhite!80!Gainsboro} \multicolumn{2}{|c|}{\myhead{a}}&
            \myhead{b} &
            \myhead{C} &
            \myhead{$\mathbf{d}$} &
            \myhead{$\mathbf{e}$}
            \\
            \hline
            f&g&h&i&j&k\\
            \hline
            \end{tabular}
    \caption{XY}
    \label{tab:XYZ}
\end{table}

\end{document} 

enter image description here

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.