5

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.

2

3 Answers 3

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}

result

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}

enter image description here

1
  • 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
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.

8
  • 5
    \newcommand*{\cnot}[1][black]{\mathrel{\color{#1}\not}} would avoid restating the current color.
    – egreg
    Commented Jun 3, 2012 at 20:55
  • 2
    Even more, the "current color" might not be black.
    – lockstep
    Commented Jun 3, 2012 at 21:00
  • do you need fontenc as part of the MWE?
    – cmhughes
    Commented Jun 3, 2012 at 21:55
  • @egreg: Hm, I always forget things like \mathrel. Commented Jun 5, 2012 at 18:46
  • 2
    @ThorstenDonig A casual user might think that T1 and fontenc are essential for the solution.
    – egreg
    Commented Jun 5, 2012 at 19:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .