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.

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:

enter image description here

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?

share|improve this question

3 Answers 3

up vote 6 down vote accepted

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}

enter image description here

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

share|improve this answer
    
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 at 4:43
1  
@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 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}

crossing out with styles

share|improve this answer

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}%
}

enter image description here

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}
share|improve this answer
    
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 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 at 12:33

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.