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.
Asked
Active
Viewed 1,950 times
5
3 Answers
5
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}

lockstep
- 250,273
-
The OP does not seem to ask about canceling complete expressions but about negating single relation symbols. For this purpose
\notis quite sufficient. Furthermore the author of »cancel« explicitly discourages users from using the package (at the very end of its manual). – Thorsten Donig Jun 05 '12 at 18:52
4
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.
Thorsten Donig
- 46,014
-
5
\newcommand*{\cnot}[1][black]{\mathrel{\color{#1}\not}}would avoid restating the current color. – egreg Jun 03 '12 at 20:55 -
2
-
-
-
@lockstep: The probability that the current color is not black is vanishingly low. – Thorsten Donig Jun 05 '12 at 18:47
-
-
2@ThorstenDonig A casual user might think that
T1andfontencare essential for the solution. – egreg Jun 05 '12 at 19:21 -
egreg has made my point- I always try and make my MWE as minimal as possible and load only the packages that are required. – cmhughes Jun 05 '12 at 20:25
2
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}
xorissao
- 70

cancelpackage manual and the disclaimer in the end. – percusse Jun 03 '12 at 20:44