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 have the following tikz style

  \tikzset{actor/.style={ rectangle, minimum size=6mm, very thick,
    draw=red!50!black!50, top color=white, bottom
    color=red!50!black!20 }
}

and I would like to have an other style which is the same but with a cross out in the rectangle. How can I achieve this ?

share|improve this question
2  
Instead of posting code snippets, it's usually preferred to post a complete minimal example document. That saves others the work of having to come up with a test document themselves. –  Jake Sep 19 '12 at 9:20
add comment

1 Answer

up vote 9 down vote accepted

You can use append after command in conjunction with the fit library to place a cross out node (which comes from the shapes.misc library) over the actor node:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes.misc, fit}

\begin{document}
\begin{tikzpicture}
\tikzset{
    actor/.style={
        rectangle, minimum size=6mm, very thick,
        draw=red!50!black!50, top color=white, bottom
        color=red!50!black!20
    },
    actor crossed out/.style={
        actor, 
        append after command={
            node [
                fit=(\tikzlastnode),
                draw=red!50!black!50,
                thick,
                inner sep=-\pgflinewidth,
                cross out
            ] {}
        }
    }
}

\node [actor] (a) {A};
\node [actor crossed out, right of = a] {B};

\end{tikzpicture}
\end{document} 

Alternatively, you can use edges in the append after command to draw the lines. This does not require any libraries:

\documentclass{article}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\tikzset{
    actor/.style={
        rectangle, minimum size=6mm, very thick,
        draw=red!50!black!50, top color=white, bottom
        color=red!50!black!20
    },
    actor crossed out/.style={
        actor, 
        append after command={
            [every edge/.append style={
                thick,
                red!50!black!50,
                shorten >=\pgflinewidth,
                shorten <=\pgflinewidth,
            }]
           (\tikzlastnode.north west) edge (\tikzlastnode.south east)
           (\tikzlastnode.north east) edge (\tikzlastnode.south west)
        }
    }
}

\node [actor] (a) {A};
\node [actor crossed out, right of = a] {B};

\end{tikzpicture}
\end{document} 
share|improve this answer
add comment

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.