表和多列的問題

表和多列的問題

我遇到了下表的問題:

\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}  

問題出在多列。如果我改為:

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

它確實有效...

哪裡有問題?

謝謝!

答案1

該問題是由您的\rule與 結合引起的,\multicolumn因為它與 位於同一單元格中\multicolumn。如果您想保留它,請將其放在另一個單元格中或\multicolumn.如果你只是想要適當的間距,你可以\strut在後面插入一個\huge.

使用\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}

產生: 在此輸入影像描述

使用\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}

產生: 在此輸入影像描述

答案2

您可以使用\extrarowheight在頂部添加一些填充全部單元格(考慮到預設行高的嚴格性,這並不是一種奢侈),或定義一個最小的以字母 為前綴的列中儲存格頂部和底部的垂直間距S

我使用命令簡化了程式碼\rowcolor,並定義了\myhead包含字體變更的命令。我冒昧地將第一行的顏色改為更好的灰色陰影:

\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} 

在此輸入影像描述

相關內容