4

I crossed out the letter K using the answer given here... cross out arbitrary cells Then I colored the row using \cellcolor, but the cell, which is crossed out is only half filled... What do I need to change to color the whole cell...?

enter image description here

This is my code...

\documentclass[titlepage=true, 12pt]{scrartcl}

\usepackage[ngerman]{babel}
\usepackage[a4paper, text={16.5cm, 25.2cm}, centering]{geometry}

\usepackage{newtxtext,newtxmath}
\setkomafont{disposition}{\normalfont\bfseries}

\usepackage[utf8]{inputenc}

\setlength{\parskip}{1.2ex}
\setlength{\parindent}{0em}

\usepackage{fancyhdr}
\pagestyle{fancy}

\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[L]{Name}
\fancyfoot[C]{\thepage}


\usepackage{filecontents}
\usepackage[autostyle]{csquotes}

\usepackage{setspace}

\usepackage{tabularx}


\usepackage{adjustbox}

\usepackage{zref-savepos}

\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{xcolor,stackengine}

\newcommand\splat[3][white]{%
  \colorbox{#1}{~~\sffamily\stackon{\fbox{\makebox[3ex]{\large\strut #2}}}{#3}~~}%
}

\usepackage{colortbl}

\newcounter{NoTableEntry}
\renewcommand*{\theNoTableEntry}{NTE-\the\value{NoTableEntry}}

\newcommand*{\strike}[2]{%
  \multicolumn{1}{#1}{%
    \stepcounter{NoTableEntry}%
    \vadjust pre{\zsavepos{\theNoTableEntry t}}% top
    \vadjust{\zsavepos{\theNoTableEntry b}}% bottom
    \zsavepos{\theNoTableEntry l}% left
    \hspace{0pt plus 1filll}%
    #2% content
    \hspace{0pt plus 1filll}%
    \zsavepos{\theNoTableEntry r}% right
    \tikz[overlay]{%
      \draw
        let
          \n{llx}={\zposx{\theNoTableEntry l}sp-\zposx{\theNoTableEntry r}sp-\tabcolsep},
          \n{urx}={\tabcolsep},
          \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})
      ;
    }% 
  }%
}




    \begin{document}

    \newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
    \newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
    \newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}

    \setlength{\extrarowheight}{5pt}
    \setlength{\tabcolsep}{6pt}

    \adjustbox{valign=t}{\begin{minipage}[t]{0.63\textwidth}

    \begin{tabular}{|C{0.8cm}|L{8cm}|}

    \hline
    A & peu de cours \\
    \hline
    B &  la confiance en soi\\
    \hline
    C &  se trouve le village du Père Noël \\
    \hline
    D & début de semestre\\
    \hline
    E &  à augmenter la fréquentation de la ville\\
    \hline
    F & des ours polaires \\
    \hline
    G & fin de semestre\\
    \hline
    H & beaucoup de cours \\
    \hline
    I & nous a permis de nous intégrer plus facilement \\
    \hline
    J & une magnifique aurore boréale \\
    \hline
    \strike{|c|}{\cellcolor{gray!30}K} &\cellcolor{gray!30} les gens sont quasiment tous bilingues en anglais \\
    \hline
    \end{tabular}

    \end{minipage}}
    \adjustbox{valign=t}{\begin{minipage}[t]{0.36\textwidth}

    \Shortstack[l]{
    \splat[gray!30]{K}{0}\splat{}{1}\splat{}{2}\splat{}{3}
    \splat{}{4}\splat{}{5}\splat{}{6}\splat{}{7}
    \splat{}{8}}

    \end{minipage}}


    \end{document}
Katharina
  • 671

2 Answers2

3

One possibility is to, instead of using \strike, use the \cancel feature of the cancel package. The only quirk is that it operates in math mode, so I needed to use $\cancel{\mbox{K}}$.

\documentclass[titlepage=true, 12pt]{scrartcl}

\usepackage[ngerman]{babel}
\usepackage[a4paper, text={16.5cm, 25.2cm}, centering]{geometry}

\usepackage{newtxtext,newtxmath,cancel}
\setkomafont{disposition}{\normalfont\bfseries}

\usepackage[utf8]{inputenc}

\setlength{\parskip}{1.2ex}
\setlength{\parindent}{0em}

\usepackage{fancyhdr}
\pagestyle{fancy}

\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[L]{Name}
\fancyfoot[C]{\thepage}


\usepackage{filecontents}
\usepackage[autostyle]{csquotes}

\usepackage{setspace}

\usepackage{tabularx}


\usepackage{adjustbox}

\usepackage{zref-savepos}

\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{xcolor,stackengine}

\newcommand\splat[3][white]{%
  \colorbox{#1}{~~\sffamily\stackon{\fbox{\makebox[3ex]{\large\strut #2}}}{#3}~~}%
}

\usepackage{colortbl}

\newcounter{NoTableEntry}
\renewcommand*{\theNoTableEntry}{NTE-\the\value{NoTableEntry}}

\newcommand*{\strike}[2]{%
  \multicolumn{1}{#1}{%
    \stepcounter{NoTableEntry}%
    \vadjust pre{\zsavepos{\theNoTableEntry t}}% top
    \vadjust{\zsavepos{\theNoTableEntry b}}% bottom
    \zsavepos{\theNoTableEntry l}% left
    \hspace{0pt plus 1filll}%
    #2% content
    \hspace{0pt plus 1filll}%
    \zsavepos{\theNoTableEntry r}% right
    \tikz[overlay]{%
      \draw
        let
          \n{llx}={\zposx{\theNoTableEntry l}sp-\zposx{\theNoTableEntry r}sp-\tabcolsep},
          \n{urx}={\tabcolsep},
          \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})
      ;
    }% 
  }%
}




    \begin{document}

    \newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
    \newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
    \newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}

    \setlength{\extrarowheight}{5pt}
    \setlength{\tabcolsep}{6pt}

    \adjustbox{valign=t}{\begin{minipage}[t]{0.63\textwidth}

    \begin{tabular}{|C{0.8cm}|L{8cm}|}

    \hline
    A & peu de cours \\
    \hline
    B &  la confiance en soi\\
    \hline
    C &  se trouve le village du Père Noël \\
    \hline
    D & début de semestre\\
    \hline
    E &  à augmenter la fréquentation de la ville\\
    \hline
    F & des ours polaires \\
    \hline
    G & fin de semestre\\
    \hline
    H & beaucoup de cours \\
    \hline
    I & nous a permis de nous intégrer plus facilement \\
    \hline
    J & une magnifique aurore boréale \\
    \hline
    \cellcolor{gray!30}$\cancel{\mbox{K}}$ &\cellcolor{gray!30} les gens sont quasiment tous bilingues en anglais \\
    \hline
    \end{tabular}

    \end{minipage}}
    \adjustbox{valign=t}{\begin{minipage}[t]{0.36\textwidth}

    \Shortstack[l]{
    \splat[gray!30]{K}{0}\splat{}{1}\splat{}{2}\splat{}{3}
    \splat{}{4}\splat{}{5}\splat{}{6}\splat{}{7}
    \splat{}{8}}

    \end{minipage}}


    \end{document}

enter image description here

One can then play games to fudge it:

\hline
\cellcolor{gray!30}\makebox[0pt]{$\cancel{\makebox[5.7ex]{%
  K\rule[-3ex]{0pt}{5.5ex}}}$} &%
  \cellcolor{gray!30} les gens sont quasiment tous bilingues en anglais \\
\hline

Here is the result

enter image description here

  • Steven Hi. I have voted two your answer +2! Excellent. – Sebastiano May 23 '17 at 12:08
  • @Sebastiano And you deserve a +2 for your enthusiasm for LaTeX. – Steven B. Segletes May 23 '17 at 12:12
  • AHAHAH. :-) I just saw but did not have to return the +2. You run, like so many others, that I know a lot and excellent work. I voted positively because they are done very well. – Sebastiano May 23 '17 at 12:15
  • @Sebastiano The desire to encourage others is a great virtue. I can always count on you for such encouragement. It is infectious. – Steven B. Segletes May 23 '17 at 12:18
  • Your solution works really well, but one of the advantages of \strike is, that the the lign is automatically adjusted to the width and height of the cell, so you don't have to play around every time, which can be quite time consuming if you need to use that code a lot... Is there a way to change it, so that the line adjust itself? – Katharina May 25 '17 at 20:39
  • 1
    @Katharina There is no easy fix. The width is approximately the width of "K" plus 2\tabcolsep. The height is approximately 2\normalbaselineskip plus a few points (unless you have modified \arraystretch). – Steven B. Segletes May 26 '17 at 01:03
  • @StevenB.Segletes thank you for that tipp! I inserted two \ spaces before and after the K and now the whole cell is gray :) – Katharina May 26 '17 at 07:12
0

With {NiceTabular} of nicematrix, you can easily draw whatever rule you want in your tabular with TikZ because nicematrix creates PGF/TikZ nodes under the cells, rows and columns of the tabular for you.

Here, the instruction to strike your cell is \tikz \draw (12-|1) -- (11-|2) ; in the \CodeAfter of the environment {NiceTabular}.

\documentclass[titlepage=true, 12pt]{scrartcl}
\usepackage[french]{babel}
\usepackage[a4paper, text={16.5cm, 25.2cm}, centering]{geometry}
\usepackage{newtxtext,newtxmath}
\usepackage{adjustbox}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{stackengine}
\usepackage{nicematrix}

\newcommand\splat[3][white]{% \colorbox{#1}{\sffamily\stackon{\fbox{\makebox[3ex]{\large\strut #2}}}{#3}}% }

\begin{document}

\setlength{\extrarowheight}{5pt} \setlength{\tabcolsep}{6pt}

\adjustbox{valign=t}{\begin{minipage}[t]{0.63\textwidth} \begin{NiceTabular}{p[c]{0.8cm}p[l]{8cm}}[hvlines,color-inside] A & peu de cours \ B & la confiance en soi\ C & se trouve le village du Père Noël \ D & début de semestre\ E & à augmenter la fréquentation de la ville\ F & des ours polaires \ G & fin de semestre\ H & beaucoup de cours \ I & nous a permis de nous intégrer plus facilement \ J & une magnifique aurore boréale \ \rowcolor{gray!30} K & les gens sont quasiment tous bilingues en anglais \ \CodeAfter \tikz \draw (12-|1) -- (11-|2) ; \end{NiceTabular} \end{minipage}} % \adjustbox{valign=t}{\begin{minipage}[t]{0.36\textwidth} \Shortstack[l]{ \splat[gray!30]{K}{0}\splat{}{1}\splat{}{2}\splat{}{3} \splat{}{4}\splat{}{5}\splat{}{6}\splat{}{7} \splat{}{8}} \end{minipage}}

\end{document}

You need several compilations.

Output of the above code

F. Pantigny
  • 40,250