Cross Out Text (Strikethrough) in LaTeX — The soul
package, ulem
package, and cancel
package
Method 1: by the \st
command of the soul
package
In LaTeX, we can use the \st
command of the soul
package1 to cross out text:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
\documentclass{article}
\usepackage{lipsum}
\usepackage{soul}
\newcommand{\mylipsum}{\lipsum[1][1-2]}
\begin{document}
\mylipsum
\st{text to be deleted}
\mylipsum
\st{text to be deleted}
\mylipsum
\end{document}
and meanwhile we can use the \setstcolor
command to set the color of the strikethrough2:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
\documentclass{article}
\usepackage{lipsum}
\usepackage{soul,xcolor}
\newcommand{\mylipsum}{\lipsum[1][1-2]}
\begin{document}
\mylipsum
\st{text to be deleted}
\mylipsum
\setstcolor{red}
\st{text to be deleted}
\mylipsum
\st{text to be deleted}
\setstcolor{black}
\mylipsum
\st{text to be deleted}
\mylipsum
\end{document}
Besides, the \st
command can be used to cross out inline equations:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
\documentclass{article}
\usepackage{lipsum,amsmath}
\usepackage{soul,xcolor}
\newcommand{\mylipsum}{\lipsum[1][1-2]}
\begin{document}
\mylipsum
\st{text to be deleted, $a^2+b^2=c^2$}
\mylipsum
\setstcolor{red}
\st{text to be deleted, $a^2+b^2=c^2$}
\mylipsum
\st{text to be deleted, $a^2+b^2=c^2$}
\setstcolor{black}
\mylipsum
\st{text to be deleted, $a^2+b^2=c^2$}
\mylipsum
\end{document}
but it cannot be used inside of the math modes, including inline math mode and display math mode, for example, the syntax like:
1
$a^2+\st{b^2=c^2}$
or
1
2
3
\begin{equation*}
a^2+\st{b^2=c^2}
\end{equation*}
will induce errors.
Method 2: by the ulem
package
The ulem
package is originally for underlining3, but the reference2 provides a way to realize strikethrough by it:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
\documentclass{article}
\usepackage{xcolor,lipsum}
\usepackage[normalem]{ulem}
\newcommand{\mylipsum}{\lipsum[1][1-2]}
\newcommand\redsout{\bgroup\markoverwith{\textcolor{red}{\rule[0.7ex]{2pt}{0.7pt}}}\ULon}
\begin{document}
\mylipsum
\redsout{text to be deleted, $a^2+b^2=c^2$}
\mylipsum
$a^2+\redsout{b^2=c^2}$
\mylipsum
\begin{equation}
a^2+\redsout{b^2=c^2}\\
\end{equation}
\end{document}
where the code
1
\newcommand\redsout{\bgroup\markoverwith{\textcolor{red}{\rule[0.7ex]{2pt}{0.7pt}}}\ULon}
is to define a new underline style to realize the effect of strikethrough. More details about this syntax can be found in the documentation of ulem
package 4.
At this time, we can see this defined command \redsout
can be used in both inline math mode and display math mode. A very flexible way.
Method 3: by the cancel
package5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
\documentclass{article}
\usepackage{lipsum}
\usepackage{cancel}
\newcommand{\mylipsum}{\lipsum[1][1-2]}
\begin{document}
% The `\cancel` command
\mylipsum
\cancel{text to be deleted, $a^2+b^2=c^2$}
\mylipsum
$a^2+\cancel{b^2=c^2}$
\mylipsum
\vspace{3em}
\begin{equation}
a^2+\cancel{b^2=c^2}\\
\end{equation}
% The `\bcancel` command
\mylipsum
\bcancel{text to be deleted, $a^2+b^2=c^2$}
\mylipsum
$a^2+\bcancel{b^2=c^2}$
\mylipsum
\begin{equation}
a^2+\bcancel{b^2=c^2}\\
\end{equation}
\vspace{3em}
% The `\xcancel` command
\mylipsum
\xcancel{text to be deleted, $a^2+b^2=c^2$}
\mylipsum
$a^2+\xcancel{b^2=c^2}$
\mylipsum
\begin{equation}
a^2+\xcancel{b^2=c^2}\\
\end{equation}
% The `\cancelto` command
\begin{equation}
\cancelto{3^2}{a^2}+\cancelto{4^2}{b^2}=\cancelto{5^2}{c^2}\\
\end{equation}
\end{document}
where6:
Also, we can use the following code in the preamble to specify the color of cancel mark:
1
2
\usepackage{xcolor}
\renewcommand\CancelColor{\color{red}}
References