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.

This is my code:

\documentclass[tikz,12pt]{standalone}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}[line width=1.5pt]
\coordinate (A) at (2,2);
\coordinate (B) at (2,1.2);
\coordinate (C) at (3,2);
\coordinate (D) at (3,1.2);
\draw[fill=white] (A) circle (0.5);
\draw[fill=white,pattern=north east lines, pattern color=black] (B) circle (0.5);
\draw[fill=white] (C) circle (0.5);
\draw[fill=white] (D) circle (0.5);
\end{tikzpicture}
\end{document}

enter image description here

When I use pattern=north east lines I can see first circle through second with pattern.

If I do not use pattern=north east lines I get what I want to see: second circle overlay first one.

But I need Second circle to be with pattern.

How this problem could be solved without using \pgfdeclarelayer{background} \pgfsetlayers{background,main}?

share|improve this question
    
I think How to avoid covering nodes with connection lines can give you the correct way to proceed. –  Claudio Fiandrino Apr 2 at 10:19

2 Answers 2

up vote 13 down vote accepted

You can use postaction and draw the patterns after filling.

\documentclass[tikz,12pt]{standalone}
\usetikzlibrary{patterns}

\begin{document}
\begin{tikzpicture}[line width=1.5pt]
\coordinate (A) at (2,2);
\coordinate (B) at (2,1.2);
\coordinate (C) at (3,2);
\coordinate (D) at (3,1.2);
\draw[fill=white] (A) circle (0.5);
\draw[fill=white,
         postaction = {pattern=north east lines,pattern color=black}] (B) circle (0.5);
\draw[fill=white] (C) circle (0.5);
\draw[fill=white] (D) circle (0.5);
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer

In Graphic Parameters: Fill Pattern section from TiKZ documentation you can read

Instead of filling a path with a single solid color, it is also possible to fill it with a tiling pattern.

Although it's not clearly stated, it looks like any pattern option replaces any previous fill option. Of course, any fill option will replace any pattern one. Just put fill=white after pattern in your code and see what happens.

Therefore, if you want a filled (non transparent) pattern, you need to draw it after (postaction) filling while node is drawn as it's shown in Harish's answer.

Another option is filling before (preaction) drawing the node and its filling pattern.

\documentclass[tikz,12pt]{standalone}
\usetikzlibrary{patterns}

\begin{document}
\begin{tikzpicture}[line width=1.5pt]
\coordinate (A) at (2,2);
\coordinate (B) at (2,1.2);
\coordinate (C) at (3,2);
\coordinate (D) at (3,1.2);
\draw[fill=white] (2,2) circle (0.5);
\draw[preaction={fill=white},
         pattern=north east lines,pattern color=black] (B) circle (0.5);
\draw[fill=white] (C) circle (0.5);
\draw[fill=white] (D) circle (0.5);
\end{tikzpicture}
\end{document}
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.