0

I'm trying to write a table in \LaTeX where I need to cross out some cells and add a color to them, to show visually the advance in a subject. I'm using this post Strike out a table cell to adequately cross table cells as I wanted, but when I try to use \cellcolor with it I can't get the expected result. For simplicity I'll write again the pieces of code that I'm using from the link above:

\documentclass{article}

\usepackage{pgf,tikz,colortbl} \usetikzlibrary{arrows} \usetikzlibrary{babel} \usetikzlibrary{calc} \usepackage{zref-savepos} % % \newcounter{NoTableEntry} \renewcommand{\theNoTableEntry}{NTE-\the\value{NoTableEntry}} % \newcommand{\notableentry}{% \multicolumn{1}{@{}c@{}|}{% \stepcounter{NoTableEntry}% \vadjust pre{\zsavepos{\theNoTableEntry t}}% top \vadjust{\zsavepos{\theNoTableEntry b}}% bottom \zsavepos{\theNoTableEntry l}% left \hspace{0pt plus 1filll}% \zsavepos{\theNoTableEntry r}% right \tikz[overlay]{% \draw[black] let \n{llx}={\zposx{\theNoTableEntry l}sp-\zposx{\theNoTableEntry r}sp}, \n{urx}={0}, \n{lly}={\zposy{\theNoTableEntry b}sp-\zposy{\theNoTableEntry r}sp}, \n{ury}={\zposy{\theNoTableEntry t}sp-\zposy{\theNoTableEntry r}sp} in (\n{llx}, \n{lly}) -- (\n{urx}, \n{ury}) (\n{llx}, \n{ury}) -- (\n{urx}, \n{lly}) ; }% }% } \begin{document} \begin{table} \centering \caption{Activities.} \begin{tabular}{|c|c|} \hline Activities & \rotatebox[origin=c]{-90}{August 2016} \ % \hline Introduction & \notableentry \ \hline \end{tabular} \label{tab:fig1} \end{table} \end{document}

Where I wrote \notableentry is where I need the cell crossed out and colored in red.

Thank's so much in advance.

  • 2
    a MWE ought to start \documentclass load all required packages and end \end{document} that's what the W(orking) means in that context. posting a fragment just makes it harder for anyone to see the issue and help – David Carlisle Dec 14 '16 at 23:48
  • see the colortbl documentation about (not) supporting stretch glue in cells the \hspace{0pt plus 1filll}% looks like it will break that rule. – David Carlisle Dec 14 '16 at 23:53
  • @DavidCarlisle Thank you! I'm sorry about the mistakes in my post, I'm pretty new posting my doubts here. Nonetheless your answer solved my problem. – R.Falcon Dec 15 '16 at 02:26

1 Answers1

1

Seeing as you have got tikz to work out the corners of the cell, you may as well not use colortbl at all and get tikz to fill in the rectangle. (Probably the tikz can be optimised to share the calculation of the coordinates but this works..)

enter image description here

\documentclass{article}

\usepackage{pgf,tikz,colortbl}
\usetikzlibrary{arrows}
\usetikzlibrary{babel}
\usetikzlibrary{calc}
\usepackage{zref-savepos}
%
%
\newcounter{NoTableEntry}
\renewcommand*{\theNoTableEntry}{NTE-\the\value{NoTableEntry}}
%
\newcommand*{\notableentry}{%
  \multicolumn{1}{@{}c@{}|}{%
    \stepcounter{NoTableEntry}%
    \vadjust pre{\zsavepos{\theNoTableEntry t}}% top
    \vadjust{\zsavepos{\theNoTableEntry b}}% bottom
    \zsavepos{\theNoTableEntry l}% left
    \hspace{0pt plus 1filll}%
    \zsavepos{\theNoTableEntry r}% right
    \tikz[overlay]{%
      \fill[red]
        let
          \n{llx}={\zposx{\theNoTableEntry l}sp-\zposx{\theNoTableEntry r}sp},
          \n{urx}={0},
          \n{lly}={\zposy{\theNoTableEntry b}sp-\zposy{\theNoTableEntry r}sp},
          \n{ury}={\zposy{\theNoTableEntry t}sp-\zposy{\theNoTableEntry r}sp}
        in
       (\n{llx}, \n{lly}) rectangle (\n{urx}, \n{ury})
      ;
      \draw[black]
        let
          \n{llx}={\zposx{\theNoTableEntry l}sp-\zposx{\theNoTableEntry r}sp},
          \n{urx}={0},
          \n{lly}={\zposy{\theNoTableEntry b}sp-\zposy{\theNoTableEntry r}sp},
          \n{ury}={\zposy{\theNoTableEntry t}sp-\zposy{\theNoTableEntry r}sp}
        in
        (\n{llx}, \n{lly}) -- (\n{urx}, \n{ury})
        (\n{llx}, \n{ury}) -- (\n{urx}, \n{lly})
      ;
    }% 
  }%
}
\begin{document}
\begin{table}
\centering
\caption{Activities.}
\begin{tabular}{|c|c|}
\hline
Activities & \rotatebox[origin=c]{-90}{August 2016} \\
%
\hline Introduction & \notableentry \\
\hline
\end{tabular}
\label{tab:fig1}
\end{table}
\end{document}
David Carlisle
  • 757,742