[Tex/LaTex] Indentation issues with highlighting cell using tikzmarkin

beamerhighlightingindentationtikz-styles

I am trying to eliminate offset/indentation issues when using tikzmarkin to highlight regions of a table.

\documentclass{beamer}

\RequirePackage{booktabs,colortbl,caption,tabularx,chngcntr, tikz, comment, subfig,xcolor}

\usepackage{lmodern}
\usepackage[beamer,customcolors]{hf-tikz}

\tikzset{hl/.style={
        set fill color=red!80!black!40,
        set border color=red!80!black,
    },
}

\begin{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
    \frametitle{Correlations}
    \vspace{-2em}
    \begin{tabular*}{1.00\textwidth}{@{\hskip\tabcolsep\extracolsep\fill}l*{6}r}
        & $\alpha$ & $ p_L $ & $\kappa$ & $\sigma$ & $\delta$ & $ \lambda $ \\
        [1.5pt]  \hline
        \tikzmarkin<3>[hl]{c1}$\alpha$  \tikzmarkend{c1}                                & \tikzmarkin<1>[hl]{a1} -0.08 \tikzmarkend{a1}   & 0.05    & -0.18    & 0.18     & -0.06    & -0.18       \\ [2pt]
        $ ~p_L $                                   & -0.07    & 0.03    & -0.08    & 0.02     & 0.09     & -0.02       \\ [2pt]
        $\varepsilon$                             & -0.31    & 0.05    & -0.33    & \tikzmarkin<2>[hl]{b1} 0.59     & 0.04     & -0.30       \\ [2pt]
        $\mu$                                     & -0.33    & 0.10    & -0.39    & 0.57 \tikzmarkend{b1}     & 0.07     & -0.40       \\ [2pt]
        $ \frac{\mu}{\varepsilon} $               & 0.23     & -0.06   & 0.47     & -0.39    & 0.24     & 0.49        \\ [2pt]
    \end{tabular*}
\end{frame}
\end{document}

For instance, the contents of the first highlighted cell (-0.08) is shifted to the left. Similarly, the bottom cell contents of the second highlighted cells are shifted left. When elements in the first column are highlighted, the contents are shifted right however. Is there a fix for this using the options of tikz? Thanks.

Best Answer

Remove the space before and after the cell content you want to highlight i.e:

Change this:

& \tikzmarkin<1>[hl]{a1} -0.08 \tikzmarkend{a1} &

to this:

&\tikzmarkin<1>[hl]{a1}-0.08\tikzmarkend{a1}&

Complete MWE of the solution:

\documentclass{beamer}

\RequirePackage{booktabs,colortbl,caption,tabularx,chngcntr, tikz, comment, subfig,xcolor}

\usepackage{lmodern}
\usepackage[beamer,customcolors]{hf-tikz}

\tikzset{hl/.style={
        set fill color=red!80!black!40,
        set border color=red!80!black,
    },
}

\begin{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
    \frametitle{Correlations}
    \vspace{-2em}
    \begin{tabular*}{1.00\textwidth}{@{\hskip\tabcolsep\extracolsep\fill}l*{6}r}
        & $\alpha$ & $ p_L $ & $\kappa$ & $\sigma$ & $\delta$ & $ \lambda $ \\[1.5pt] \hline
    \tikzmarkin<3>[hl]{c1}$\alpha$\tikzmarkend{c1}& \tikzmarkin<1>[hl]{a1}-0.08\tikzmarkend{a1} & 0.05 & -0.18 & 0.18 & -0.06 & -0.18 \\[2pt]
        $ ~p_L $ & -0.07 & 0.03 & -0.08 & 0.02  & 0.09  & -0.02 \\ [2pt]
        $\varepsilon$ & -0.31 & 0.05  & -0.33 & \tikzmarkin<2>[hl]{b1}0.59 & 0.04 & -0.30 \\[2pt]
        $\mu$ & -0.33 & 0.10 & -0.39 & 0.57\tikzmarkend{b1} & 0.07 & -0.40 \\[2pt]
        $ \frac{\mu}{\varepsilon} $ & 0.23  & -0.06 & 0.47  & -0.39 & 0.24 & 0.49 \\[2pt]
    \end{tabular*}
\end{frame}
\end{document}

first

second