1

How do I cross out maths to show they vanish with evenly oriented diagonal lines (i.e., all lines parallel?)

I don't like how the crossing lines appear due to size of the expressions. It doesn't matter if the expressions are wide or narrow especially in fractions. Is there a way to modify the diagonal lines? Or is there a better package or option?

Here is my MWE:

\documentclass{article}

\usepackage{tikz} \usepackage[makeroom]{cancel}

\begin{document}

[ \frac{1}{1} + \cancel{\frac{1}{2}} + \cancel{\frac{1}{3}} + \cancel{\frac{1}{4}} + \cancel{\frac{1}{5}} + \cancel{\dots} + \cancel{\frac{1}{n-1}} + \cancel{\frac{1}{n}} ] \end{document}

Output

SolidMark
  • 1,389
  • you could make them all the same slope but what slope do you want, all near-vertical like the first 4, so just going through the centre of the fraction? – David Carlisle Jan 19 '22 at 10:38
  • but this seems to be a duplicate of the question in the related list in the sidebar: https://tex.stackexchange.com/questions/571374/cancel-or-bcancel-draws-non-parallel-lines-in-math-mode-looking-for-better-so?rq=1 – David Carlisle Jan 19 '22 at 10:39
  • Yeah if possible. The link you gave is partially helpful but didn't solve my problem. – SolidMark Jan 19 '22 at 11:00
  • could you expand on the differences, it seemed to be the same question? – David Carlisle Jan 19 '22 at 11:35
  • Lines don't align when I use the solution code from the link you provided with my given example. I am not sure what modifications do I need to make here. – SolidMark Jan 19 '22 at 12:46

1 Answers1

3

This uses \cancelbox to store a predesigned common cancel slash. \mycancel centers the slash over the contents. It uses \mathsavebox from here.

\documentclass{article}
\usepackage{mathtools}
\usepackage{mathstyle}
\usepackage[makeroom]{cancel}

\makeatletter \newcommand{\mathsavebox}[2]{% \setbox#1=\hbox{$\m@th\currentmathstyle#2$}% } \makeatother

\newsavebox{\cancelbox} \savebox{\cancelbox}{$\cancel{\phantom{\dfrac{1}{1}}}$}

\newcommand{\mycancel}[1]{\mathsavebox{1}{#1}{\usebox1\hspace{-\wd1}\makebox[\wd1]{\usebox\cancelbox}}}

\begin{document}

[ \frac{1}{1} + \mycancel{\frac{1}{2}} + \mycancel{\frac{1}{3}} + \mycancel{\frac{1}{4}} + \mycancel{\frac{1}{5}} + \mycancel{\dots} + \mycancel{\frac{1}{n-1}} + \mycancel{\frac{1}{n}} ] \end{document}

demo

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
  • I had to waste my time using tikz nodes to position maths and cross them out diagonally with their own anchors. Yet they were poorly spaced. – SolidMark Jan 19 '22 at 20:12