2

I am trying to sort out a multicolumn table using tabular. Since I am not so experienced in latex, I've relied on tablesgenerator.com to generate the code, which is:

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

This results in the following table:

enter image description here

This is more or less what I need, but for some reason, the cell size of the last cell in the first row (party labels) is a bit shorter than the cells in the following rows. It's a bit annoying because it ruins the layout of the table.

Any ideas how to get equal widths for the cells in the last column?

Thanks!

PS: If I use the option suggested by the website \usepackage[table,xcdraw]{xcolor} it throws an error of conflicting options, so I set it up as \usepackage[table]{xcolor}. I use all this with beamer.

UPDATE - compilable/reproducible code:

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

2 Answers 2

3

cause of your problem is @{} on the begin and end of columns definitions. if you delete them, then black color will become the same in both first two rows.

However, table is set on very complicate way. i try clean up your code and use standard names for white and black color:

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

enter image description here

0
3

With {NiceTabular} of 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}

Output of the above code

You won't see thin white lines, whatever PDF viewer you use.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .