[Tex/LaTex] \cancel draws under thing being canceled

cancelcolor

I'm trying to use \cancel from the cancel package to strike out some colored text but it is apparent that the diagonal line is drawn first so it doesn't do a very good job of canceling.
enter image description here

Minimal example.

\documentclass{article}
\usepackage{xcolor,cancel}
\begin{document}
\leavevmode
\cancel{\textcolor{red}{T}}
\textcolor{red}{T}\llap{\cancel{\phantom{T}}}
\end{document}

I can obviously use the \llap, but that is suboptimal. Is there a better way?

Best Answer

Using Tikz :

\newcommand{\cancel}[1]{%
    \tikz[baseline=(tocancel.base)]{
        \node[inner sep=0pt,outer sep=0pt] (tocancel) {#1};
        \draw[red] (tocancel.south west) -- (tocancel.north east);
    }%
}%

This is a \cancel{test}

Another possibility with Tikz is to use the strike out shape:

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{shapes.misc}


\begin{document}
Strike \tikz[baseline] \node [strike out,draw=red,anchor=text] {me}; out!
\end{document}

Using pstricks, in the pstricks-add package :

%in preamble
\usepackage{pstricks,pstricks-add}

%in document
%example taken from pstricks-add documentation
\psCancel[linecolor=red]{Tikz :-)}

Edit 1 : I just realized that the \psCancel macro draws the mark before the text to cancel, same as for the cancel package. If you want the mark above the text, I guess you should use Tikz.

Edit 2 : Incorporated suggestions about baseline into the Tikz code

Related Question