1

Sometimes I have some plotmarks and some lines later. So the marks becomes unnice.

How can I say something like: "every mark to the foreground"?

Note that I do not want to set the \coordinates to the foreground (they where used just for the example) or maybe some other tricks. I really want to know, how to set the plotmarks to the foreground.

enter image description here

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{plotmarks}
\begin{document}

\begin{tikzpicture}[ Mark/.style={ mark=*, mark size=1.5pt, mark options={fill=yellow} }, ] \coordinateA at (0,0); \coordinateB at (2,3); \coordinateC at (1,1);

\foreach \P in {A,B,C}{ \draw[] plot[Mark] coordinates{(\P)}; }

\draw[] (A) -- (B) -- (C); \end{tikzpicture} \end{document}

cis
  • 8,073
  • 1
  • 16
  • 45

1 Answers1

2

Here are three possible solutions:

  • draw lines on background layer, with the tikz library backgrounds loaded,
  • draw marks on foreground layer, with the option on above layer from package tikz-layers used, and
  • draw filled circles as \nodes, then the overlapping is auto avoided (see pgfmanual v3.1.7a, sec. 17.11 Connecting Nodes: Using Nodes as Coordinates).
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds, plotmarks}

\begin{document}

\begin{tikzpicture}[ Mark/.style={ mark=*, mark size=1.5pt, mark options={fill=yellow} }, ] \coordinateA at (0,0); \coordinateB at (2,3); \coordinateC at (1,1);

\foreach \P in {A,B,C}{ \draw[] plot[Mark] coordinates{(\P)}; }

\begin{scope}[on background layer] \draw[] (A) -- (B) -- (C); \end{scope} \end{tikzpicture} \end{document}

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{plotmarks}
\usepackage{tikz-layers}

\begin{document}
\begin{tikzpicture}[
  Mark/.style={ mark=*, mark size=1.5pt, mark options={fill=yellow} },
]
  \coordinate[](A) at (0,0);
  \coordinate[](B) at (2,3);
  \coordinate[](C) at (1,1);

  \begin{scope}[on above layer]
    \foreach \P in {A,B,C}{
      \draw[]  plot[Mark]  coordinates{(\P)};
    }
  \end{scope}

  \draw[] (A) -- (B) -- (C);
\end{tikzpicture}
\end{document}
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{plotmarks}
\usepackage{tikz-layers}

\begin{document}

\begin{tikzpicture}[
  Mark/.style={ circle, draw, inner sep=0pt, minimum size=3pt, fill=yellow },
]
  \node[Mark] (A) at (0,0) {};
  \node[Mark] (B) at (2,3) {};
  \node[Mark] (C) at (1,1) {};

  \draw[] (A) -- (B) -- (C);
\end{tikzpicture}
\end{document}

All three ways give the same output enter image description here

Moreover, if you have many coordinates to link one-by-one, then

  • \draw[mark=*, ...] plot coordinates {(0,0) (2,3) (1,1)};
  • or even pgfplots might help;
muzimuzhi Z
  • 26,474
  • Ah, ok. TYVM, good answer to this question. I have a new idea, similar to this problem: https://tex.stackexchange.com/questions/575252/tikz-how-to-use-draw-options-only-for-coordinates-which-exists – cis Dec 16 '20 at 11:49