8

I am trying to include some boxes around numbers in a table. I am using the method exactly described on the answer to question below:

Beamer, annotated tables using Tikzmark

The issue is that the first cell of the area surrounded by the box gets an extra space (if you see the example above you will see it). That's quite annoying. Why does it happen? How to solve it?

  • It seems that inserting \unskip at the beginning of the cell (i.e. before the word "Slider" in the answer you linked) removes the extra space.. – campa Dec 14 '15 at 11:17
  • The issue is that I have many boxes per table, starting at different cells, and doing that in all of them is very painful. – phdstudent Dec 14 '15 at 11:22
  • It is an extra space created by hf-tikz (so that the box has a non-zero inner separation, I guess). – Bibi Dec 14 '15 at 14:40
  • And any general solution to the issue? – phdstudent Dec 14 '15 at 14:45
  • Well, due to the box, the width of the element in the first cell is increased, even if the box is not drawn... So either put the same space in front of all the first cells, or wait for the hf-tikz maintainer (or someone better than me ^^) to come up with a solution. – Bibi Dec 14 '15 at 14:56
  • @volcompt you could ask to hf-tikz maintainer directly. Its possible him response to you. – juanuni Dec 14 '15 at 15:55
  • It has nothing to do with the drawing or non-drawing of the box. It has nothing to do with the box at all. The box is overlaid on the page. It does not take up any space at all. This is an overlay in the TikZ sense - not the Beamer one. That is, it uses remember picture, overlay in the options to tikzpicture. Stuff created that way effectively takes no space as it is put on top of whatever else is there. The problem is just spurious spaces in the definition of the command. – cfr Dec 16 '15 at 03:22
  • @AritroPathak Is this comment here still relevant or outdated in the meantime, and would you like to remove it? – Stefan Kottwitz Oct 16 '20 at 16:35

1 Answers1

11

The definition of the macros in the package fail to comment line endings in all of the necessary places. Since TeX interprets these as spaces, spaces are inserted.

The definition of \tikzmarkin involves numerous, nested conditional clauses. Here, I just tried to pick the one relevant to you and redefine that.

The fix involves adding this to the preamble after loading hf-tikz:

\RenewDocumentCommand{\tikzmarkin}{r<> o m D(){\belowrightoff} D(){\aboveleftoff}}{%
  \IfNoValueTF{#2}{%true-val
    \only<#1>{\tikz[remember picture,overlay]
      \draw[line width=1pt,rectangle,disable rounded corners,fill=\fcol,draw=\bcol]
      (pic cs:#3) ++(#4) rectangle (#5) node [anchor=base] (#3){}
      ;}%
  }{%false-val
    \only<#1>{\tikz[remember picture,overlay]
      \draw[line width=1pt,rectangle,disable rounded corners,fill=\fcol,draw=\bcol,#2]
      (pic cs:#3) ++(#4) rectangle (#5) node [anchor=base] (#3){}
      ;}}%
}

Note that my fix consists of the addition of two % signs at the end of lines. Obviously, this should be fixed for all cases and not just the Beamer-rounded-corners-fill-etc.-etc. one, but that is really best done in the package by its maintainer.

The results look like this:

slide 1

slide 2

Complete code for example:

\documentclass{beamer}
\mode<presentation>
{
\usetheme{CambridgeUS}
\usecolortheme{dolphin}
\setbeamercovered{transparent}
}
\usepackage{colortbl}
\usepackage{amsmath,amssymb,amsthm} %%% INCLUDE
\usepackage{multirow,booktabs,dcolumn}
\usepackage[beamer,customcolors]{hf-tikz}
\usetikzlibrary{calc}
\tikzset{hl/.style={%
    set fill color=red!80!black!40,
    set border color=red!80!black,
  },
}
\RenewDocumentCommand{\tikzmarkin}{r<> o m D(){\belowrightoff} D(){\aboveleftoff}}{%
  \IfNoValueTF{#2}{%true-val
    \only<#1>{\tikz[remember picture,overlay]
      \draw[line width=1pt,rectangle,disable rounded corners,fill=\fcol,draw=\bcol]
      (pic cs:#3) ++(#4) rectangle (#5) node [anchor=base] (#3){}
      ;}%
  }{%false-val
    \only<#1>{\tikz[remember picture,overlay]
      \draw[line width=1pt,rectangle,disable rounded corners,fill=\fcol,draw=\bcol,#2]
      (pic cs:#3) ++(#4) rectangle (#5) node [anchor=base] (#3){}
      ;}}%
}
\begin{document}

\begin{frame}{Regression Results}{Participation}

\begin{table}
\resizebox{0.86\textwidth}{0.4\textheight}{
\begin{tabular}{lcccccc} \hline
& \multicolumn{3}{c}{Dependent Variable:} &  \multicolumn{3}{c}{Dependent Variable:} \\
& \multicolumn{3}{c}{Effort>0} &  \multicolumn{3}{c}{Effort>5} \\
\cline{2-4} \cline{5-7}
Variables & (1) & (2) & (3) & (4) & (5) & (6) \\
\hline
 &  &  &  &  &  &  \\
\tikzmarkin<2>[hl]{H1}Slider & -0.019 & -0.031 & -0.038 & -0.037 & -0.051 & -0.055 \\
 & (0.069) & (0.068) & (0.068) & (0.068) & (0.067) & (0.066)\tikzmarkend{H1}\\
Early Departure  & -0.143** & -0.160** & -0.147** & -0.204*** & -0.222*** & -0.209*** \\
 & (0.070) & (0.070) & (0.070) & (0.069) & (0.068) & (0.069) \\
Pause  & -0.427*** & -0.430*** & -0.425*** & -0.694*** & -0.697*** & -0.691*** \\
 & (0.068) & (0.068) & (0.067) & (0.067) & (0.066) & (0.066) \\
20-Minute  & -0.036 & -0.040 & -0.037 & -0.035 & -0.040 & -0.036 \\
 & (0.069) & (0.068) & (0.068) & (0.067) & (0.066) & (0.066) \\
Threshold  & -0.284*** & -0.282*** & -0.272*** & -0.266*** & -0.263*** & -0.254*** \\
 & (0.068) & (0.068) & (0.067) & (0.067) & (0.066) & (0.066) \\
Flat Wage  & 0.037 & 0.020 & 0.031 & 0.056 & 0.038 & 0.041 \\
 & (0.069) & (0.069) & (0.069) & (0.068) & (0.067) & (0.067) \\
Effort Choice & -0.606*** & -0.608*** & -0.601*** & -0.766*** & -0.769*** & -0.759*** \\
 & (0.068) & (0.068) & (0.068) & (0.067) & (0.066) & (0.066) \\
Constant & 0.963*** & 1.111*** & 0.989*** & 0.944*** & 1.102*** & 1.051*** \\
 & (0.049) & (0.064) & (0.159) & (0.048) & (0.062) & (0.155) \\
 &  &  &  &  &  &  \\
Observations & 434 & 434 & 434 & 434 & 434 & 434 \\
R-squared & 0.277 & 0.298 & 0.316 & 0.429 & 0.448 & 0.463 \\
\% invested in Risk Task & N & Y & Y & N & Y & Y \\
Controls & N & N & Y & N & N & Y \\
\hline
\multicolumn{7}{c}{ Standard errors in parentheses} \\
\multicolumn{7}{c}{ *** p$<$0.01, ** p$<$0.05, * p$<$0.10} \\
\end{tabular}
\begin{tikzpicture}[remember picture,overlay]
\node<2>[left=-3pt,anchor=west,yshift=1.5ex,font=\small] at (pic cs:H1) {Comment};
\end{tikzpicture}
}
\end{table}

\end{frame}

\end{document}
cfr
  • 198,882