表格多列-奇怪的单元格大小

表格多列-奇怪的单元格大小

我正在尝试使用 tabular 整理多列表格。由于我对 latex 不太熟悉,所以我依赖于tablesgenerator.com生成代码,即:

% Please add the following required packages to your document preamble:
% \usepackage{booktabs}
% \usepackage{multirow}
% \usepackage[table,xcdraw]{xcolor}
% If you use beamer only pass "xcolor=table" option, i.e. \documentclass[xcolor=table]{beamer}
\begin{table}[]
\begin{tabular}{@{}cc
>{\columncolor[HTML]{000000}}c 
>{\columncolor[HTML]{000000}}c @{}}
\multicolumn{2}{c}{} & \multicolumn{2}{c}{\cellcolor[HTML]{000000}{\color[HTML]{FFFFFF} Party Labels}} \\
\multicolumn{2}{c}{\multirow{-2}{*}{}} & {\color[HTML]{FFFFFF} High stability} & {\color[HTML]{FFFFFF} Low stability} \\
\cellcolor[HTML]{000000}{\color[HTML]{FFFFFF} } & \cellcolor[HTML]{000000}{\color[HTML]{FFFFFF} High stability} & \cellcolor[HTML]{EFEFEF}{\color[HTML]{000000} Stable systems} & \cellcolor[HTML]{EFEFEF}{\color[HTML]{000000} Ephemeral parties} \\
\multirow{-2}{*}{\cellcolor[HTML]{000000}{\color[HTML]{FFFFFF} \begin{tabular}[c]{@{}c@{}}Programmatic\\   positions\end{tabular}}} & \cellcolor[HTML]{000000}{\color[HTML]{FFFFFF} Low stability} & \cellcolor[HTML]{EFEFEF}{\color[HTML]{000000} Empty labels} & \cellcolor[HTML]{EFEFEF}{\color[HTML]{000000} Unstable systems}
\end{tabular}
\end{table}

得出下表:

在此处输入图片描述

这或多或少是我需要的,但由于某种原因,第一行最后一个单元格的单元格大小(派对标签) 比后面几行的单元格要短一些。这有点烦人,因为它破坏了表格的布局。

有什么想法可以使最后一列的单元格宽度相等吗?

谢谢!

PS:如果我使用网站建议的选项,\usepackage[table,xcdraw]{xcolor}它会抛出一个选项冲突的错误,所以我将其设置为\usepackage[table]{xcolor}。我将所有这些都与一起使用beamer

更新 -可编译/可重现的代码:

\documentclass[xcolor=table]{beamer}

\mode<presentation> {

\usetheme{Madrid}}

\usepackage{booktabs} % Allows the use of \toprule, \midrule and \bottomrule in tables
\usepackage{multirow}
\usepackage[table]{xcolor}

\begin{document}

\begin{frame}

\begin{table}[]
\begin{tabular}{@{}cc
>{\columncolor[HTML]{000000}}c 
>{\columncolor[HTML]{000000}}c @{}}
\multicolumn{2}{c}{} & \multicolumn{2}{c}{\cellcolor[HTML]{000000}{\color[HTML]{FFFFFF} Party Labels}} \\
\multicolumn{2}{c}{\multirow{-2}{*}{}} & {\color[HTML]{FFFFFF} High stability} & {\color[HTML]{FFFFFF} Low stability} \\
\cellcolor[HTML]{000000}{\color[HTML]{FFFFFF} } & \cellcolor[HTML]{000000}{\color[HTML]{FFFFFF} High stability} & \cellcolor[HTML]{EFEFEF}{\color[HTML]{000000} Stable systems} & \cellcolor[HTML]{EFEFEF}{\color[HTML]{000000} Ephemeral parties} \\
\multirow{-2}{*}{\cellcolor[HTML]{000000}{\color[HTML]{FFFFFF} \begin{tabular}[c]{@{}c@{}}Programmatic\\   positions\end{tabular}}} & \cellcolor[HTML]{000000}{\color[HTML]{FFFFFF} Low stability} & \cellcolor[HTML]{EFEFEF}{\color[HTML]{000000} Empty labels} & \cellcolor[HTML]{EFEFEF}{\color[HTML]{000000} Unstable systems}
\end{tabular}
\end{table}

\end{frame}

\end{document} 

答案1

问题的原因@{}在于列定义的开始和结束。如果删除它们,那么前两行的黑色将变得相同。

但是,表格的设置方式非常复杂。我尝试清理您的代码并使用白色和黑色的标准名称:

\documentclass[xcolor=table]{beamer}

\mode<presentation> {
    \usetheme{Madrid}}

\usepackage{booktabs} % Allows the use of \toprule, \midrule and \bottomrule in tables
\usepackage{multirow}

\begin{document}

\begin{frame}
    \begin{table}
\begin{tabular}{>{\color{white}}c
                >{\color{white}}c
                >{\columncolor{black}}c
                >{\columncolor{black}}c}
\multicolumn{2}{c}{} & \multicolumn{2}{c}{\cellcolor{black}{\color{white} Party Labels}}    \\
\multicolumn{2}{c}{} & \color{white} High stability     & \color{white} Low stability       \\
\cellcolor{black}{Programmatic}  & \cellcolor{black}{High stability}
    & \cellcolor{white}{Stable systems}  & \cellcolor{white}{Ephemeral parties}             \\
\cellcolor{black}{positions}    & \cellcolor{black}{Low stability}
    & \cellcolor{white}{Empty labels}   & \cellcolor{white}{Unstable systems}
\end{tabular}
\end{table}

在此处输入图片描述

答案2

与。{NiceTabular}nicematrix

\documentclass{beamer}
\mode<presentation>{\usetheme{Madrid}}
\usepackage{nicematrix}

\begin{document}

\newcolumntype{C}{>{\columncolor{black}\color{white}}c}

\begin{frame}
\begin{NiceTabular}{CCcc}[corners,colortbl-like]
\RowStyle[nb-rows=2,rowcolor=black,color=white]{}& & \Block{1-2}{Party Labels} \\
& & High stability & Low stability \\
Programmatic & High stability & Stable systems & Ephemeral parties \\
positions & Low stability & Empty labels & Unstable systems 
\end{NiceTabular}
\end{frame}

\end{document}

上述代码的输出

无论您使用哪种 PDF 查看器,都不会看到细白线。

相关内容