The cancel package
Strikes through parts of a formula with a diagonal line: \cancel, \bcancel, \xcancel and \cancelto.
Loading the package
\usepackage{cancel}The package draws a line through a term to show that it cancels out, for example a common factor in a fraction. The slope of the line follows the width and height of the term.
\cancel, \bcancel and \xcancel work in math and in text. \cancelto draws an arrow to a value and works in math mode only.
Main commands
\cancel{x} | Line from bottom left to top right. |
\bcancel{x} | Line from top left to bottom right. |
\xcancel{x} | Both lines, forming an X. |
\cancelto{0}{x} | Arrow through the term that points to the value 0. |
\renewcommand{\CancelColor}{\color{red}} | Colours the lines; needs xcolor or color. |
\usepackage[makeroom]{cancel} | Adds horizontal space for the value of \cancelto, which otherwise can overlap the next symbol. |
Complete example
\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{cancel}
\renewcommand{\CancelColor}{\color{red}}
\begin{document}
\[
\frac{(x + 1)\cancel{(x - 2)}}{(x + 3)\cancel{(x - 2)}} = \frac{x + 1}{x + 3}
\]
\[
a + \bcancel{b} - \bcancel{b} = a,
\qquad
x^2 + \cancelto{0}{\varepsilon x} = x^2,
\qquad
\xcancel{2 + 2 = 5}
\]
\end{document}Compiled with pdfLaTeX from TeX Live 2023.
Pitfalls
- The lines add no horizontal space, so the value of
\canceltocan print over the symbol to its right. The optionmakeroomreserves the space. \canceltoin text mode gives Missing $ inserted.
Related pages
- How-to Cancel terms in an equation in LaTeX
- How-to Strikethrough text in LaTeX
- How-to Fractions in LaTeX
- Package
xcolor