如何在单个表格中结合底部对齐和顶部对齐?

如何在单个表格中结合底部对齐和顶部对齐?

我想构建一个很长的比较表,其中包含很多要比较的点,每个点可能包含多个子类别。这就是我想要的表格的样子

在此处输入图片描述

方法比较应底部对齐(理想情况)。但是,主要类别的编号也是底部对齐的。我希望它顶部对齐,同时保持方法比较的底部对齐。用于p{<width>}描述列不起作用

\documentclass{IEEEtran}

    \usepackage{ragged2e}
    \usepackage{tabularx}

        \newcolumntype{C}{>{\arraybackslash\Centering}X}

    \newcommand{\multcolhsize}[1]{\dimexpr #1\hsize + #1\tabcolsep + #1\tabcolsep - 2\tabcolsep \relax}

    \usepackage{booktabs}
    \usepackage{makecell}

    \usepackage{mathtools}
    \usepackage{adjustbox}

    \usepackage{rotating}

    \usepackage{enumitem}
    \newlist{tabenum}{enumerate}{1}
    \setlist[tabenum]{wide=0pt, 
        nosep, 
        leftmargin=*,
        label*=\alph*.,
        after=\vspace{-\baselineskip},
        before=\vspace{0mm}}

\begin{document}

\begin{table}[htp]

    \caption{Impact on the Grid, PEVs and Environment for Different PEV Charging and Discharging Strategies}
    \label{table:comparison_impact}

    \centering

    \begin{tabularx}{\columnwidth}{r b{4.2cm} *{6}{C}}

        \toprule

        &
        &
        \multicolumn{6}{>{\hsize=\multcolhsize{6}}C}{Charging Strategy}
        \\
        \cmidrule(l){3-8}

        &
        Description &
        \adjustbox{rotate=90}{Method 1} &
        \adjustbox{rotate=90}{Method 2} &
        \adjustbox{rotate=90}{Method 3} &
        \adjustbox{rotate=90}{Method 4} &
        \adjustbox{rotate=90}{Method 5} &
        \adjustbox{rotate=90}{Method 6}
        \\
        \cmidrule(r){2-2} \cmidrule(l){3-8}

        1- &
        Main Category Explained Over Multiple Lines &
        &
        &
        &
        &
        &
        \\
        \addlinespace[1mm]

        &
        \begin{tabenum}[series=table, start=1]

            \item Subcategory A - Long Multiline Description Across 3 Lines

        \end{tabenum} &
        N &
        Y &
        N &
        Y &
        N &
        Y
        \\
        \addlinespace[1mm]

        &
        \begin{tabenum}[resume*=table]

            \item Subcategory B - Multiline Description

        \end{tabenum} &
        L &
        Y &
        L &
        Y &
        L &
        Y
        \\
        \addlinespace[1mm]

        &
        \begin{tabenum}[resume*=table]

            \item Subcategory C

        \end{tabenum} &
        L &
        Y &
        L &
        Y &
        L &
        Y
        \\
        \addlinespace[1mm]

        \bottomrule

    \end{tabularx}

\end{table}

\end{document}

答案1

以下是稍微不同的建议,使用宏来设置子表类别:

在此处输入图片描述

\documentclass{IEEEtran}

\usepackage{ragged2e}
\usepackage{tabularx}

\newcolumntype{C}{>{\arraybackslash\Centering}X}

\newcommand{\multcolhsize}[1]{\dimexpr #1\hsize + #1\tabcolsep + #1\tabcolsep - 2\tabcolsep \relax}

\usepackage{booktabs}

\newcounter{tablenum}
\renewcommand{\thetablenum}{\alph{tablenum}}% Representation
\newcommand{\newtablenum}{%
  \stepcounter{tablenum}% Increment counter
  \thetablenum.%
}
\newcommand{\tabsubcategory}[1]{%
  \hspace*{5mm}% Fake left margin
  \parbox[b]{35mm}{\raggedright
    \makebox[0mm][r]{\makebox[5mm][l]{\newtablenum}}% Set sub-table category number in margin
    #1}%
}

\begin{document}

\begin{table}
  \centering
  \caption{Impact on the Grid, PEVs and Environment for Different PEV Charging and Discharging Strategies}
  \begin{tabularx}{\columnwidth}{r >{\raggedright\arraybackslash}p{40mm} *{6}{C} }
    \toprule
    & & \multicolumn{6}{>{\hsize=\multcolhsize{6}}C}{Charging Strategy/Method} \\
    \cmidrule(l){3-8}
    & Description & 1 & 2 & 3 & 4 & 5 & 6 \\
    \cmidrule(r){2-2} \cmidrule(l){3-8}
    1- & Main Category Explained Over Multiple Lines \\
    \addlinespace[1mm]
    & \tabsubcategory{Subcategory A - Long Multiline Description Across 3 Lines}
      & N & Y & N & Y & N & Y \\
    \addlinespace[1mm]
    & \tabsubcategory{Subcategory B - Multiline Description} 
      & L & Y & L & Y & L & Y \\
    \addlinespace[1mm]
    & \tabsubcategory{Subcategory C} 
      & L & Y & L & Y & L & Y \\
    \bottomrule
  \end{tabularx}
\end{table}

\end{document}

如果您在表格中有多个需要子类别的元素,请\setcounter{tablenum}{0}在新列表之前添加。这类似于之前start = 1enumitem您定义的接口。

这里的主要思想是使用“伪列”自动设置子表类别编号,同时仍使整个单元格结构在适当宽度[b]内底对齐。使用这种窄列通常可以更好地表示文本,否则很容易出现换行问题。\parbox\raggedright

相关内容