2

I would like to have two middle columns in a grey background (constant) and on the top to overlay a square to highlight something in particular (just to enter at some point). An example of of what I would like follows - numbers are different from my MVE.

    \documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{psfrag}
\usepackage{tikz}
\usetikzlibrary{intersections,patterns,pgfplots.fillbetween}
\usetikzlibrary{decorations.pathreplacing}
\usepackage{booktabs, dcolumn}
\usepackage{fontawesome}
\usetheme{CambridgeUS}
\usecolortheme{seahorse}
\usepackage{multirow}
\usepackage{hyperref}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\usepackage{datetime}
\usepackage[scale=2]{ccicons}
\newdateformat{monthyeardate}{%
  \monthname[\THEMONTH], \THEYEAR}
\usepackage{animate}
%\usepackage{colortbl}
\usepackage[beamer,customcolors]{hf-tikz}
\usetikzlibrary{calc}
\title{beamer}
% To set the highlighting boxes red.
\tikzset{%
    hl/.style={
align=center,
set fill color=white,
    set border color=red,
 right offset={0.35,-0.2},
  },
hl2/.style={
align=center,
set fill color=gray!10,
    set border color = white,
right offset={0.35,-0.2},
  },
}


\begin{document}

\maketitle

\begin{frame}
\begin{table}
    \centering
\begin{tabular}{l*{6}{c}}
\toprule
                   & \multicolumn{2}{c}{x} & \tikzmarkin<1->[hl2]{c} \multicolumn{2}{c}{y} & \multicolumn{2}{c}{555} \\
                  \cmidrule(r){2-3} \cmidrule(r){4-5} \cmidrule(r){6-7} &\multicolumn{1}{c}{Probit}&\multicolumn{1}{c}{Heckman Prob}&\multicolumn{1}{c}{Probit}&\multicolumn{1}{c}{Heckman Prob}&\multicolumn{1}{c}{Probit}&\multicolumn{1}{c}{Heckman Prob}\\
                  & (1) & (2) & (3) & (4) & (5) &(6) \\

\midrule
wwwww &      75  &    85   &      850  &      980&    00   &       800\\
                    &    80   &    1400   &    250  &    70 &    199   &   60   \\

\multicolumn{7}{l}{cccccccccccccccc} \\                    
1                   &  \tikzmarkin<2>[hl]{bH5}   50 &      30 &    40 &     10 \tikzmarkend{c}\tikzmarkend{bH5} &      20       5\\
\end{tabular}
\end{table}
\end{frame}
\end{document}

enter image description here

Y_gr
  • 3,322
  • \tikzmarkin{...}...\tikzmarkend{...} cannot be put over \cellcolor or columncolor, consequently it is covered by them. your attempt seems to be request for new hf-tikz features` – Zarko May 09 '19 at 13:11
  • @Zarko indeed... Any ideas, how to solve it though? Even without `hf-tikz' – Y_gr May 09 '19 at 13:14
  • 1
    Could you perhaps make your code compilable and clearly indicate which column should be highlighted? –  May 09 '19 at 13:20
  • My code collapses. And that's why I don't know how to solve this issue? Probably it's related to what Zarko said above. I want to highlight columns 3 and 4 including their title (see multicolumn{2}{c}{y} on my mve). – Y_gr May 09 '19 at 13:22

2 Answers2

1

As starting point: use tikzmark library (recent version). After removing not used packages from preamble and comment others, which are load by beamer the mwe (minimal working example) is:

\documentclass[xcolor=table]{beamer}
\usetheme{CambridgeUS}
\usecolortheme{seahorse}
%\usepackage[utf8]{inputenc}    % default at recent version of document classes
%\usepackage{psfrag}
\usepackage{fontawesome}
\usepackage{tikz}
\usetikzlibrary{fit,            % new
                tikzmark}       % new
\usepackage{booktabs,
            cellspace,          % new
            multirow}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}
%\addparagraphcolumntypes{X}  % in case of use tabularx

%\usepackage{multirow} doesn't exist %\usepackage{hyperref} loaded by beamer %\usepackage{colortbl} loaded by beamer option "xcolor=table"

\begin{document} %\maketitle

\begin{frame} \begin{table} \centering \renewcommand{\aboverulesep}{0pt} \renewcommand{\belowrulesep}{0pt} \begin{tabular}{l cc >{\columncolor{gray!30}}Sc >{\columncolor{gray!30}}Sc cc} \toprule & \multicolumn{2}{c}{x} & \multicolumn{2}{c}{\cellcolor{gray!30}{y}} & \multicolumn{2}{c}{555} \ \cmidrule(r){2-3} \cmidrule{4-5} \cmidrule(l){6-7} & Probit & HP & Probit & HP & Probit & HP \ & (1) & (2) & (3) & (4) & (5) & (6) \ \midrule wwwww & 75 & 85 & 850 & 980 & 00 & 800 \ & 80 & 1400 & 250 & 70 & 199 & 60 \ \multicolumn{3}{l}{cccccccccccccccc} & & & & \ 1 & \tikzmarknode{a}{50} & & 40 & 10 & \tikzmarknode{b}{20} & 5 \ \midrule[\heavyrulewidth] \multicolumn{7}{l}{HP: Heckman Prob} \end{tabular} \end{table} \begin{tikzpicture}[overlay,remember picture] \node[draw=red, thick, inner sep=2pt, rounded corners, fit=(a) (b)] {}; \end{tikzpicture} \end{frame} \end{document}

after two compilation it gives:

enter image description here

Zarko
  • 296,517
  • 1
    It does not work for me. There's an error with \end{frame}. – domi May 09 '19 at 14:20
  • do you you have installed recent tikz package? I test my mwe again and it works (please test edited answer) – Zarko May 09 '19 at 14:27
  • it doesn't work for me either... It places the red box at the end of the slide. not on the table – Y_gr May 09 '19 at 14:40
  • to obtain correct result you need to compile mwe twice as i said in my answer. i test my mwe with using tikz 2019/04/04 v3.1.2. i suggest to update your latex installation. – Zarko May 09 '19 at 14:58
  • I've updated tikz and all the packages. Now it gives this error: ! Undefined control sequence. @sharp ->\cellcolor {gray!30}{y} – Y_gr May 11 '19 at 18:11
  • 1
    @Y_gr, whit exactly the same code ad it is in answer? I just update my latex installation (in it is among others new pgf˙,tikzmarkandl3kernellibrary) and it still works as expected: no errors, no warning, no bad boxes. You might have somewhere an outdated packages. Do you also upgradetikzmarkpackage? I use 64-bit MikTeX on w10 machine. for update I useMIkTeX Console. Can you show log file of your compilation of my MWE? – Zarko May 11 '19 at 18:53
1

Here is a way to do such tabular with {NiceTabular} of nicematrix. You need several compilations.

\documentclass{beamer}
\usetheme{CambridgeUS}
\usecolortheme{seahorse}
\usepackage{fontawesome}

\usepackage{nicematrix}

\usepackage{tikz} \usetikzlibrary{fit}

\usepackage{booktabs}

\begin{document}

\begin{frame} \begin{table} \centering \renewcommand{\arraystretch}{1.2} \begin{NiceTabular}{lcccccc}[tabularnote = HP: Heckman Prob] \CodeBefore \columncolor{gray!30}{4,5} \Body \toprule & \Block{1-2}{x} && \Block{1-2}{y} && \Block{1-2}{555} \ \cmidrule(r){2-3} \cmidrule{4-5} \cmidrule(l){6-7} & Probit & HP & Probit & HP & Probit & HP \ & (1) & (2) & (3) & (4) & (5) & (6) \ \midrule wwwww & 75 & 85 & 850 & 980 & 00 & 800 \ & 80 & 1400 & 250 & 70 & 199 & 60 \ \rlap{cccccccccccccccc} \ 1 & 50 & & 40 & 10 & 20 & 5 \ \bottomrule \CodeAfter \tikz \node[draw=red, thick, inner sep = 2pt, rounded corners, fit=(7-2) (7-6)] {} ; \end{NiceTabular} \end{table} \end{frame} \end{document}

Output of the above code

F. Pantigny
  • 40,250