I often use command \not
just to cancel off symbols in my equations and i would need an advice on how to change the color of this command.
3 Answers
Some similar command for obtaining colored \cancelto (some math package is probably missing)
\documentclass{article}
\usepackage{xcolor}
\usepackage{cancel}
\newcommand\crossout[3][black]{\renewcommand\CancelColor{\color{#1}}\cancelto{#2}{#3}}
\begin{document}
$\crossout[red]{\infty}{a^2} + \crossout[blue]{0}{b^2} = \crossout[green]{\infty}{c^2} $
\end{document}
As mentioned by percusse in the comments, it is better to use cancel
package since \not
can not strike out more than one variable (say (x+y)
). You can define a macro to change the color of strike line as your need:
\documentclass{article}
\usepackage{xcolor}
\usepackage[thicklines]{cancel}
% \renewcommand*{\CancelColor}{\color{red}}%%if only one color is enough
\newcommand*{\mynot}[1]{\renewcommand{\CancelColor}{\color{#1}}\cancel}
\begin{document}
\[
\mynot{red}{\in}
\]
\[
(\mynot{green}{x+y})(x-y)
\]
\[
\mynot{black}{x+y}
\]
\mynot{blue}{This} is cancelled out. % \cancel works in text mode also.
\end{document}
-
The OP does not seem to ask about canceling complete expressions but about negating single relation symbols. For this purpose
\not
is quite sufficient. Furthermore the author of »cancel« explicitly discourages users from using the package (at the very end of its manual). Commented Jun 5, 2012 at 18:52
A very simple method would be to temporarily change the text color and then switch back to black. This can be done by a new command.
\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\newcommand*{\cnot}[1][black]{\color{#1}\not\color{black}}
\begin{document}
\[
\cnot[red]\in
\]
\end{document}
The new command takes an arbitrary color as optional argument.
cancel
package manual and the disclaimer in the end.