Cancel terms in an equation in LaTeX (cancel)
The cancel package strikes through a part of a formula: \cancel{x} draws a diagonal line through its argument. \cancelto{0}{x} draws an arrow that points to a value.
Preamble
The snippets on this page need these lines before \begin{document}:
\usepackage{cancel}Strike through a term
\cancel{...} draws a line from the bottom left to the top right of its argument.
\[
\frac{\cancel{3} \cdot 5}{\cancel{3} \cdot 7} = \frac{5}{7}
\qquad
\cancel{x} + y - \cancel{x} = y
\]Change the formula
The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.
Other directions
\bcancel{...} draws the line from the top left to the bottom right, and \xcancel{...} draws both lines as a cross.
\[
\bcancel{a + b}
\qquad
\xcancel{a + b}
\]Change the formula
The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.
Arrow to a value
\cancelto{value}{term} strikes through the term with an arrow and prints the value at its tip. It works only in math mode.
\[
f(x) = x^2 + \cancelto{0}{\frac{1}{x}}
\]Coloured lines
Redefine \CancelColor to colour the line and leave the term black. The colour command needs the xcolor package.
Complete document:
\documentclass{article}
\usepackage{xcolor}
\usepackage{cancel}
\renewcommand{\CancelColor}{\color{red}}
\begin{document}
\[
\frac{\cancel{a} b}{\cancel{a} c} = \frac{b}{c}
\]
\end{document}Pitfalls
\cancel,\bcanceland\xcancelalso work on a word in normal text, but the word cannot break across lines. For struck-out text see Strikethrough text in LaTeX.
Compiled with pdfLaTeX from TeX Live 2023.
Related pages
- Package
cancel - Package
xcolor - How-to Strikethrough text in LaTeX
- How-to Fractions in LaTeX