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.

The following document has two tikzpictures in it, and they result in slightly different output. Why is this? I don't understand how the use of draw works in one but not the other. In the first one, the outline shows up and the rectangle is filled; in the second one just the labels "A" and "B" appear.

\documentclass[a4paper]{amsart}

\usepackage{fullpage,tikz}
\xdefinecolor{lightgrey}{RGB}{220,220,220}

\begin{document}

\begin{center}\begin{tikzpicture}
[ box/.style = {draw, rectangle, inner sep = 3mm, fill = lightgrey}
  ]
\node (A) at (0,0) [box] {$A$};
\node (B) at (2cm,0) [box] {$B$};
\draw [->] (A.east) -- (B.west);
\end{tikzpicture}\end{center}

\begin{center}\begin{tikzpicture}
\begin{scope}[draw, rectangle, inner sep = 3mm, fill = lightgrey]
    \node (A) at (0,0) {$A$};
    \node (B) at (2cm,0) {$B$};
\end{scope}
\draw [->] (A.east) -- (B.west);
\end{tikzpicture}\end{center}

\end{document}
share|improve this question

1 Answer 1

up vote 2 down vote accepted

What's happening is that the default style of a node is going unchanged; the parameters you set on the scope don't apply to anything. To make it apply, you need to specify that it's the style for a node, using every node/.style:

\begin{center}\begin{tikzpicture}
  \begin{scope}[every node/.style={ draw
                                  , rectangle
                                  , inner sep = 3mm
                                  , fill      = lightgrey }]
      \node (A) at (0,0)   {$A$} ;
      \node (B) at (2cm,0) {$B$} ;
  \end{scope}
  \draw [->] (A.east) -- (B.west);
\end{tikzpicture}\end{center}

You could also remove the scope block and put the options directly after the tikzpicture environment, as you did in the first block with box/.style, unless you want to have nodes with other styles.

share|improve this answer

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.