# How to cross out a child of a node in a tikz tree?

Consider this simple tikz tree:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{trees,shapes,snakes}

\begin{document}

\tikzstyle{mynode} = [text width=4em, text centered]
\begin{tikzpicture}[]

\node{My Root}
child{node[mynode]{Good Morning}}
child{node[mynode, cross out]{Good Afternoon}}
child{node[mynode]{Good Evening}}
\end{tikzpicture}

\end{document}


This code produces the following:

However, I was expecting that the "Good afternoon" node should be crossed out, since there was something similar here.

How can I make a cancelling 'X' appear over that particular node?

-

You need to put ,draw along with cross out:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{trees,shapes,decorations}

\begin{document}

\tikzstyle{mynode} = [text width=4em, text centered]
\begin{tikzpicture}

\node{My Root}
child{node[mynode]{Good Morning}}
child{node[mynode, cross out,draw]{Good Afternoon}}
child{node[mynode]{Good Evening}};

\end{tikzpicture}

\end{document}


If you want colour, use draw=red or any colour.

-
Thanks, that was exactly what I needed, and the most simple solution. Could you provide a quick explanation why the 'draw' had to be added? – geo909 Sep 5 '14 at 4:43
@geo909 A node needs draw to have its borders drawn. Try \node {ABC}; and \node[draw]{ABC};. You will see the difference. Without draw only the contents are displayed. Otherwise, it is only a \path, a line without ink. – Harish Kumar Sep 5 '14 at 4:46

This is based on Jesse's answer but uses a style definition rather than nesting tikzpicture environments:

\documentclass[tikz]{standalone}

\usetikzlibrary{trees,shapes.misc}
\begin{document}

\begin{tikzpicture}[
mynode/.append style={text width=4em, align=center},
tcancel/.append style={draw=#1, cross out, inner sep=1pt},
]

\node{My Root}
child{node[mynode]{Good Morning}}
child{node[mynode,tcancel=red]{Good Afternoon}}
child{node[mynode]{Good Evening}};
\end{tikzpicture}

\end{document}


-

This is one possible solution where \tcancel macro was defined. #1 = color preferred. #2 is the content.

\newcommand{\tcancel}[2][black]{%
\begin{tikzpicture}
\node[draw=#1,cross out,inner sep=1pt] (a){#2};
\end{tikzpicture}%
}


Code

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{trees,shapes,snakes}
\usetikzlibrary{shapes.misc}
\newcommand{\tcancel}[2][black]{%
\begin{tikzpicture}
\node[draw=#1,cross out,inner sep=1pt] (a){#2};
\end{tikzpicture}%
}
\begin{document}

\tikzstyle{mynode} = [text width=4em, text centered]
\begin{tikzpicture}[]

\node{My Root}
child{node[mynode]{Good Morning}}
child{node[mynode]{\tcancel[red]{Good Afternoon}}}
child{node[mynode]{Good Evening}};
\end{tikzpicture}

\end{document}

-
Isn't it problematic to use a tikzpicture within another one? That is, I've seen this said though I don't understand TikZ well enough to know. (On the other hand, this seems to be what happens if you use symbols from tikzsymbols in a tikzpicture and that seems to work OK.) – cfr Sep 3 '14 at 12:14
Hi @cfr, I am aware of your remark and this link tex.stackexchange.com/q/51193/34618. In addtion, I also tried (but failed just now) to find a 200 or 500 bounty question that I saw a couple of days ago in this site using nested tikz and got bounty. Personally, I do use nested tikz and did not get me errors. – Jesse Sep 3 '14 at 12:33