在长表环境中使用多列进行嵌套列式单元格合并

在长表环境中使用多列进行嵌套列式单元格合并

下表设置如下。我想通过逐列合并表格单元格来合并第 1-3 列中的重复值。但是,正如您所见,单元格的合并处于不同的级别或在每个考虑的列中跨越不同数量的单元格

    \begin{longtable}[!htbp]{ |m{2cm} m{3.7cm} m{2cm} | m{1.8cm} m{1.8cm} m{1.8cm}| }
 \hline
 \textbf{Rating-level} & \textbf{Rating category} & \textbf{Credit risk} & \textbf{Fitch \newline (original)} & \textbf{S\&P \newline (original)} & \textbf{Moody's \newline (original)} \\
 \hline
    \rowcolor{YellowGreen}IG & Highest-grade & Lowest & AAA & AAA & Aaa \\
    \rowcolor{YellowGreen}IG & High grade & Very low & AA+ & AA+ & Aa1 \\
    \rowcolor{YellowGreen}IG & High grade & Very low & AA & AA & Aa2 \\
    \rowcolor{YellowGreen}IG & High grade & Very low & AA- & AA- & Aa3 \\
    \rowcolor{YellowGreen}IG & Upper medium grade & Low & A+ & A+ & A1 \\
    \rowcolor{YellowGreen}IG & Upper medium grade & Low & A & A & A2 \\
    \rowcolor{YellowGreen}IG & Upper medium grade & Low & A- & A- & A3 \\
    \rowcolor{YellowGreen}IG & Medium grade & Moderate & BBB+ & BBB+ & Baa1 \\
    \rowcolor{YellowGreen}IG & Medium grade & Moderate & BBB & BBB & Baa2 \\
    \rowcolor{YellowGreen}IG & Medium grade & Moderate & BBB- & BBB- & Baa3 \\ 
    \hline
    \rowcolor{Apricot}Non-IG & Speculative grade & Substantial & BB+ & BB+ & Ba1 \\
    \rowcolor{Apricot}Non-IG & Speculative grade & Substantial & BB & BB & Ba2 \\
    \rowcolor{Apricot}Non-IG & Speculative grade & Substantial & BB- & BB- & Ba3 \\
    \rowcolor{Apricot}Non-IG & Speculative grade & High & B+ & B+ & B1 \\
    \rowcolor{Apricot}Non-IG & Speculative grade & High & B & B & B2 \\
    \rowcolor{Apricot}Non-IG & Speculative grade & High & B- & B- & B3 \\
    \rowcolor{Apricot}Non-IG & Highly speculative grade & Very high & CCC+ & CCC+ & Caa1 \\
    \rowcolor{Apricot}Non-IG & Highly speculative grade & Very high & CCC & CCC & Caa2 \\
    \rowcolor{Apricot}Non-IG & Highly speculative grade & Very high & CCC- & CCC- & Caa3 \\
    % \rowcolor{Apricot}Non-IG & & & & & & \\
    \rowcolor{Apricot}Non-IG & Highly speculative grade & Likely in or \newline near default & CC & CC & \\ 
    % \rowcolor{Apricot}Non-IG & & & & & & \\
    \rowcolor{Apricot}Non-IG & Highly speculative grade & Likely in or \newline near default & & & Ca \\
    % \rowcolor{Apricot}Non-IG & & & & & & \\
    \rowcolor{Apricot}Non-IG & Highly speculative grade & Likely in or \newline near default & C & C & \\   
    \hline
    \rowcolor{Red}Default & Default & In default & D & D & C \\
 \hline
\caption{Numeric ratings mapping table} 
% needs to go inside longtable environment
\label{tab:4thlongtable}
\end{longtable}

我尝试了几个小时在不同层次上堆叠多列命令,但没有一个能给我想要的输出。澄清一下,在第 1 列, 我想拥有3 个堆叠电池(IG、非IG、Def),在第 2 栏因此7 个堆叠电池以及第 3 栏因此9 格。不知何故,我尝试的每种方法都完全搞乱了表格布局,合并了行和列。

非常感谢任何指点!

答案1

我猜测,以下内容更接近预期的输出:

在此处输入图片描述

\documentclass{article}
\usepackage{geometry}
\usepackage[dvipsnames]{xcolor}
\usepackage{nicematrix}
\NiceMatrixOptions{cell-space-limits = 0.5\tabcolsep}

\begin{document}
\begin{table}
\centering
\caption{Numeric ratings mapping table} 
\label{tab:4thlongtable}
    \begin{NiceTabular}{ llllll }[hvlines, %
                                  code-before={%
                                     \rowcolor{YellowGreen}{2-11}
                                     \rowcolor{Apricot}{12-23}
                                     \rowcolor{Red}{24}}]
 \textbf{\Block{1-1}{Rating-\\ level}} & \textbf{\Block{1-1}{Rating\\ category}} & \textbf{\Block{1-1}{Credit risk}} & \textbf{\Block{1-1}{Fitch \\ (original)}} & \textbf{\Block{1-1}{S\&P \\ (original)}} & \textbf{\Block{1-1}{Moody's \\ (original)}} \\
    \Block[l]{10-1}{IG}     & Highest-grade                                & Lowest                                        & AAA  & AAA  & Aaa \\
                            & \Block[l]{3-1}{High grade}                   & \Block[l]{3-1}{Very low}                      & AA+  & AA+  & Aa1 \\
                            &                                              &                                               & AA   & AA   & Aa2 \\
                            &                                              &                                               & AA-  & AA-  & Aa3 \\
                            & \Block[l]{3-1}{Upper medium\\ grade}         & \Block[l]{3-1}{Low}                           & A+   & A+   & A1 \\
                            &                                              &                                               & A    & A    & A2 \\
                            &                                              &                                               & A-   & A-   & A3 \\
                            & \Block[l]{3-1}{Medium grade}                 & \Block[l]{3-1}{Moderate}                      & BBB+ & BBB+ & Baa1 \\
                            &                                              &                                               & BBB  & BBB  & Baa2 \\
                            &                                              &                                               & BBB- & BBB- & Baa3 \\ 
    \Block[l]{12-1}{Non-IG} & \Block[l]{6-1}{Speculative\\ grade}          & \Block[l]{3-1}{Substantial}                   & BB+  & BB+  & Ba1 \\
                            &                                              &                                               & BB   & BB   & Ba2 \\
                            &                                              &                                               & BB-  & BB-  & Ba3 \\
                            &                                              & \Block[l]{3-1}{High}                          & B+   & B+   & B1 \\
                            &                                              &                                               & B    & B    & B2 \\
                            &                                              &                                               & B-   & B-   & B3 \\
                            & \Block[l]{6-1}{Highly \\speculative\\ grade} & \Block[l]{3-1}{Very high}                     & CCC+ & CCC+ & Caa1 \\
                            &                                              &                                               & CCC  & CCC  & Caa2 \\
                            &                                              &                                               & CCC- & CCC- & Caa3 \\
                            &                                              & \Block[l]{3-1}{Likely in\\ or near\\ default} & CC   & CC   & \\ 
                            &                                              &                                               &      &      & Ca \\
                            &                                              &                                               & C    & C    & \\   
    Default                 & Default                                      & In default                                    & D    & D    & C \\
\end{NiceTabular}
\end{table}
\end{document}

答案2

我不知道如何添加图片,所以请看下面我目前使用您的解决方案得到的结果。我设法以一种方式编译表格,使单元格按列合并看起来像您的示例中的那样,但不知何故,列宽超出了范围。我尝试使用允许在表格环境中指定列宽的初始列类型(p{2cm}m{2cm})手动调整它们,但这没有用。

在看了几个小时后pkg 文档,我还没有找到任何可行的解决方案。如果您有任何想法,我很乐意听取您对这个后续问题的反馈。谢谢!

在此处输入图片描述

相关内容