2

MWE:

\documentclass[]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usetikzlibrary{plotmarks}
\begin{document}
\begin{tikzpicture}
\begin{axis}
  \addplot[mark=*] coordinates
  {(0,0)};
  \node[blue] at (0,0) {\pgfuseplotmark{*}};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}
  \addplot[mark=pentagon*] coordinates
{(0,0)};
\node[red] at (0,0) {\pgfuseplotmark{pentagon*}};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

As you can see in the first picture both markers are at the same position, but not in the second. What do I have to do to get the same positioning of the marker in the node as the one which is plotted with \addplot?

Update: Version numbers from log file:

Package: pgfplots 2015/05/02 v1.12.1 Data Visualization (1.12.1)
Package: pgf 2013/12/18 v3.0.0 (rcs-revision 1.14)
File: pgflibraryplotmarks.code.tex 2013/07/20 v3.0.0 (rcs-revision 1.13)

Other questions (this is more or less a duplicate):

Hotschke
  • 5,300
  • 5
  • 33
  • 63

1 Answers1

2

That is due to the fact that plot marks in PGF are prepared for use inside of drawing instructions. They are not prepared for use in text-mode.

If you want to use drawing instructions in text mode, you have to surround them by a picture, for example as follows

\documentclass[]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usetikzlibrary{plotmarks}
\begin{document}
\begin{tikzpicture}
\begin{axis}
  \addplot[mark=pentagon*] coordinates
{(0,0)};
\node[red] at (0,0) {\tikz \pgfextra{\pgfuseplotmark{pentagon*}};};
\end{axis}
\end{tikzpicture}
\end{document}
  • Thanks for your help. Does the inline \tikz environment add overhead which should be avoided? Compilation time starts to get a bit slow. – Hotschke Aug 03 '15 at 10:04
  • I suppose it does, yes. Do you really need nodes? You could use shifts to position your markers, followed by \pgfuseplotmark. That would have considerably less overhead. – Christian Feuersänger Aug 03 '15 at 10:07
  • No, I don't need a node. Is \shift a command? Sorry, I am not familiar with the syntax of pgf. – Hotschke Aug 03 '15 at 10:12
  • Ah, ok! I thought you where about to apply an expert operation. These commands like \pgfuseplotmark are quite advanced stuff and require familiarity with the PGF basic layer (i.e. the complicated part of PGF). Given that you try to achieve something, I recommend that you ask a question "how to I achieve XYZ using pgfplots/tikz" and listen for advice. That said, you should familiarize yourself with TikZ as such, i.e. chapter III of the pgfmanual. It is simpler. Perhaps TikZ's plot styles are what you need? Aside from that, the pgfplots manual might also address your use-cases. – Christian Feuersänger Aug 03 '15 at 10:15
  • I have found another way of resolving it: \node[red] at (0,0) {\nullfont\pgfuseplotmark{pentagon*}};. This is mentioned in following answer http://tex.stackexchange.com/a/235222/8917. – Hotschke Aug 03 '15 at 10:21
  • do you think the mentioned missing % in http://tex.stackexchange.com/a/235222/8917 will be added into mainline of the plotmarks library, so this question becomes redundant? – Hotschke Aug 03 '15 at 10:28
  • I have already added the missing % chars to all affected plot marks. Nevertheless, the solution which adds the markers directly into the text is actually unsupported... I do not know if there are any caveats with it, but it is certainly luck that it works. Normally, you need a picture to draw stuff. – Christian Feuersänger Aug 03 '15 at 15:54