3

I'm currently trying to TeX up a Sieve of Eratosthenes example on the integers 2-100. I'm already using the ulem and cancel packages to give me horizontal and diagonal strikethroughs but I need a vertical strikethrough as well which would go through the same point as the horizontal and diagonal strikethroughs.

It doesn't have to be a general solution so one that works for 2-digit numbers in math-mode will suffice.

\documentclass[pdf]{beamer}
\usepackage{ulem}
\usepackage{cancel}
\newcommand{\strike}[1]{\text{\sout{$#1$}}}
\begin{document}
\begin{array}{c c c c c c c c c c}
    & \cancel{2\:} & \strike{3\:} & \cancel{4\:} & \bcancel{5\:} & \strike{\cancel{6\:}} & 7\: & \cancel{8\:} & \strike{9\:} & \xcancel{10}\\
    11 & \strike{\cancel{12}} & 13 & \cancel{14} & \bcancel{\strike{15}} & \cancel{16} & 17 & \strike{\cancel{18}} & 19 & \xcancel{20}\\
    \strike{21} & \cancel{22} & 23 & \strike{\cancel{24}} & \bcancel{25} & \cancel{26} & \strike{27} & \cancel{28} & 29 & \strike{\xcancel{30}}\\
    31 & \cancel{32} & \strike{33} & \cancel{34} & \bcancel{\textcolor{red}{35}} & \strike{\cancel{36}} & 37 & \cancel{38} & \strike{39} & \xcancel{40}\\
    41 & \strike{\cancel{42}} & 43 & \cancel{44} & \bcancel{\strike{45}} & \cancel{46} & 47 & \strike{\cancel{48}} & 49 & \xcancel{50}\\
    \strike{51} & \cancel{52} & 53 & \strike{\cancel{54}} & \bcancel{55} & \cancel{56} & \strike{57} & \cancel{58} & 59 & \strike{\xcancel{60}}\\
    61 & \cancel{62} & \strike{63} & \cancel{64} & \bcancel{65} & \strike{\cancel{66}} & 67 & \cancel{68} & \strike{69} & \xcancel{\textcolor{red}{70}}\\
    71 & \strike{\cancel{72}} & 73 & \cancel{74} & \bcancel{\strike{75}} & \cancel{76} & 77 & \strike{\cancel{78}} & 79 & \xcancel{80}\\
    \strike{81} & \cancel{82} & 83 & \strike{\cancel{84}} & \bcancel{85} & \cancel{86} & \strike{87} & \cancel{88} & 89 & \strike{\xcancel{90}}\\
    91 & \cancel{92} & 93 & \cancel{94} & \bcancel{95} & \strike{\cancel{96}} & 97 & \cancel{98} & \strike{99} & \xcancel{100}\\
\end{array}
\end{document}

What I'd like to do is add horizontal strikes to the multiples of 7 now but can't seem to do it nicely. I've tried using something like

\newcommand{\hstrike}[1]{\strike{#1}\!\mid}

or

\newcommand{\hstrike}[1]{| \! \strike{#1}}

But it screws up the rest of the formatting and that's not changed if I use \mkern instead of \!.

4
  • Related: Sieve of Eratosthenes in TikZ
    – Werner
    Jan 20, 2015 at 1:38
  • I was thinking about using TikZ but concluded that it would get far too cumbersome, as those examples seem to bear out. Especially as I want to do a different orientation of strikethrough for each prime < 10 in order to properly motivate the Sieve of Eratosthenes-Legendre.
    – Stijn
    Jan 20, 2015 at 1:44
  • Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – cfr
    Jan 20, 2015 at 2:44
  • Have done so. It's a bit of a mess unfortunately but I think all the salient details are there.
    – Stijn
    Jan 20, 2015 at 2:56

1 Answer 1

3

I created \vstrike{} and used in on "7" and "93". I also redefined all your cancel routines to make them of uniform rule thickness and length, and going through the same intersection point.

EDITED to demonstrate the Full Monty on "101".

\documentclass[pdf]{beamer}
\usepackage{stackengine,graphicx}
\def\stacktype{L}
\def\useanchorwidth{T}
%\usepackage{ulem}
\newcommand\xcancel[1]{\bcancel{\cancel{#1}}}
\newcommand\bcancel[1]{\stackon[7pt]{#1}{\rotatebox{-30}{\rule{2.9ex}{1pt}}}}
\newcommand\cancel[1]{\stackon[0pt]{#1}{\rotatebox{30}{\rule{2.9ex}{1pt}}}}
\newcommand\strike[1]{\stackon[3.3pt]{#1}{\rule{2.9ex}{1pt}}}
\newcommand\vstrike[1]{\stackon{#1}{\smash{\rule[-3pt]{1pt}{2.9ex}}}}
\begin{document}
\[
\begin{array}{c c c c c c c c c c}
    & \cancel{2} & \strike{3} & \cancel{4} & \bcancel{5} & \strike{\cancel{6}} & \vstrike{7}\: & \cancel{8} & \strike{9} & \xcancel{10}\\
    11 & \strike{\cancel{12}} & 13 & \cancel{14} & \bcancel{\strike{15}} & \cancel{16} & 17 & \strike{\cancel{18}} & 19 & \xcancel{20}\\
    \strike{21} & \cancel{22} & 23 & \strike{\cancel{24}} & \bcancel{25} & \cancel{26} & \strike{27} & \cancel{28} & 29 & \strike{\xcancel{30}}\\
    31 & \cancel{32} & \strike{33} & \cancel{34} & \bcancel{\textcolor{red}{35}} & \strike{\cancel{36}} & 37 & \cancel{38} & \strike{39} & \xcancel{40}\\
    41 & \strike{\cancel{42}} & 43 & \cancel{44} & \bcancel{\strike{45}} & \cancel{46} & 47 & \strike{\cancel{48}} & 49 & \xcancel{50}\\
    \strike{51} & \cancel{52} & 53 & \strike{\cancel{54}} & \bcancel{55} & \cancel{56} & \strike{57} & \cancel{58} & 59 & \strike{\xcancel{60}}\\
    61 & \cancel{62} & \strike{63} & \cancel{64} & \bcancel{65} & \strike{\cancel{66}} & 67 & \cancel{68} & \strike{69} & \xcancel{\textcolor{red}{70}}\\
    71 & \strike{\cancel{72}} & 73 & \cancel{74} & \bcancel{\strike{75}} & \cancel{76} & 77 & \strike{\cancel{78}} & 79 & \xcancel{80}\\
    \strike{81} & \cancel{82} & 83 & \strike{\cancel{84}} & \bcancel{85} & \cancel{86} & \strike{87} & \cancel{88} & 89 & \strike{\xcancel{90}}\\
    91 & \cancel{92} & \vstrike{93} & \cancel{94} & \bcancel{95} & \strike{\cancel{96}} & 97 & \cancel{98} & \strike{99} & \xcancel{100}\\
\strike{\vstrike{\xcancel{101}}}
\end{array}
\]
\end{document}

enter image description here

3
  • It's not sitting right for me. I've attached an image of how it's being rendered dl.dropboxusercontent.com/u/16453478/strikeout.jpg
    – Stijn
    Jan 20, 2015 at 3:54
  • 1
    @Stijn Did you forget or misspell \def\stacktype{L} in the preamble? Jan 20, 2015 at 3:57
  • 1
    Ah no, but I stupidly put it above \usepackage{stackengine}. Everything's sorted now, thanks!
    – Stijn
    Jan 20, 2015 at 4:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .