How to avoid intersection of elements in tikz

Draw them in the order you want them displayed. Just because you define the coordinates at the start doesn't mean you have to draw them then. Indeed, it can make for cleaner picture code to set up all the coordinates at the start as just coordinates and then to do the drawing afterwards. This gives greater control over things like the order in which things are drawn.

\documentclass{article}
%\url{http://tex.stackexchange.com/q/335249/86}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\coordinate (a) at (0,0);
\coordinate (b) at (3,0);
\coordinate (c) at (4,3);
\coordinate (d) at (1,2);
\draw [fill=gray](a) -- (b) -- (d) -- cycle;
\draw (b) -- (c) -- (d) -- cycle;
\foreach \coord/\pos in {
  a/left,
  b/right,
  c/right,
  d/left%
} {
  \fill (\coord) circle[radius=3pt];
  \node[\pos=1mm] at (\coord) {\(\coord\)};
}
\end{tikzpicture}
\end{document}

Result:

Quad with coordinates


Here's a third option which requires neither re-ordering your code nor loading an additional library.

This relies on the fact that the black circles are darker than the grey fill. Given that, we can add blend mode=darken to the command which adds the fill and the grey will not paint over the darker circles behind.

\documentclass[border=10pt,multi,tikz]{standalone}
\begin{document}
\begin{tikzpicture}
  [
    point/.style={circle,thick,draw=black,fill=black,inner sep=0pt,minimum width=6pt,minimum height=6pt},
  ]
  \node (a) [point, label={[label distance=-.6cm]0:$a$}] at (0,0) {};
  \node (b) [point, label={[label distance=0cm]0:$b$}] at (3,0) {};
  \node (c) [point, label={[label distance=.-.5cm]5:$c$}] at (4,3) {};
  \node (d) [point, label={[label distance=-.5cm]5:$d$}] at (1,2) {};
  \draw [blend mode=darken, fill = gray] (a.center) -- (b.center) -- (d.center) -- cycle;
  \draw (b.center) -- (c.center) -- (d.center) -- cycle;
\end{tikzpicture}
\end{document}

tweaking apparent order with a <code>blend mode</code>


You can use the backgrounds library to refer to a layer behind the dots.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}
        \begin{tikzpicture}
            [ point/.style={circle,thick,draw=black,fill=black,inner sep=0pt,minimum width=6pt,minimum height=6pt}, ]
            \node (a)[point,label={[label distance=-.6cm]0:$a$}] at (0,0) {};
            \node (b)[point,label={[label distance=0cm]0:$b$}] at (3,0) {};
            \node (c)[point,label={[label distance=.-.5cm]5:$c$}] at (4,3) {};
            \node (d)[point,label={[label distance=-.5cm]5:$d$}] at (1,2) {};
\begin{scope}[on background layer]
            \draw [fill = gray](a.center) -- (b.center) -- (d.center) -- cycle;
            \draw (b.center) -- (c.center) -- (d.center) -- cycle;
\end{scope}
        \end{tikzpicture}
\end{document}

enter image description here

Tags:

Fill

Tikz Pgf