Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
Have a look at the cancel package manual and the disclaimer in the end. –  percusse Jun 3 '12 at 20:44
    
Related Question: Diagonal strikeout starting too low and ending too high. –  Peter Grill Jun 4 '12 at 0:31

2 Answers 2

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.

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

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

share|improve this answer
    
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). –  Thorsten Donig Jun 5 '12 at 18:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.