53

The below is part of my TikZ picture:

\begin{tikzpicture}
\draw (0,0)--(10,0);
\filldraw (0,0) circle (3pt);
\end{tikzpicture}

I want to place a "square mark" to denote the point at (10,0). How can I place a square mark? Is there anything like

\filldraw (10,0) square (3pt);

In addition, how may I place a "triangle mark"?

2
  • 2
    Perhaps the 'plot coordinates' path instruction, combined with 'mark=...' is something for you. There is a huge plot mark library which includes, among others, square and triangle markers. Jul 24, 2012 at 20:17
  • 2
    You can add a square with \filldraw (10,0) rectangle ++(3pt,3pt);. Adding [yshift=-1.5pt] will center it vertically as the circle is. Jul 24, 2012 at 20:22

1 Answer 1

59

Three solutions: the first one, using the basic shapes circle and rectangle, and the regular polygon shape from the shapes library (as in Peter Grill's comment). The second and third ones use the plotmarks library; in the second one, the line and the marks are drawn independently (the marks are placed using \nodes with \pgfuseplotmark); in the third solution, the plot coordinates syntax is used, together with the mark=<mark> option (as in Christian Feuersänger's comment):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{plotmarks}

\begin{document}

\begin{tikzpicture}
\draw (0,0)--(10,0);
\filldraw (0,0) circle (3pt);
\filldraw ([xshift=-2pt,yshift=-2pt]10,0) rectangle ++(4pt,4pt);
\node[fill=black,regular polygon, regular polygon sides=3,inner sep=1.5pt] at (5cm,0) {};

\draw (0,-1)--(10,-1);
\node at (0,-1) {\pgfuseplotmark{*}};
\node at (5cm,-1) {\pgfuseplotmark{triangle*}};
\node at (10cm,-1) {\pgfuseplotmark{square*}};

\draw[mark=*] plot coordinates {(0,-2)} -- plot[mark=triangle*] coordinates {(5cm,-2)} --
  plot[mark=square*] coordinates {(10cm,-2)};
\end{tikzpicture}

\end{document}

enter image description here

The following code shows how to change the size and color of the marks for the second and third solutions:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{plotmarks}

\begin{document}

\begin{tikzpicture}
\draw (0,-1)--(10,-1);
\node[mark size=3pt,color=red] at (0,-1) {\pgfuseplotmark{*}};
\node[mark size=5pt,color=blue] at (5cm,-1) {\pgfuseplotmark{triangle*}};
\node[mark size=4pt,color=olive] at (10cm,-1) {\pgfuseplotmark{square*}};

\draw[mark=*,mark size=3pt,mark options={color=olive}] plot coordinates {(0,-2)} 
  -- plot[mark=triangle*,mark options={color=blue}] coordinates {(5cm,-2)} 
  -- plot[mark=square*,mark size=4pt,mark options={color=red}] coordinates {(10cm,-2)};
\end{tikzpicture}

\end{document}

enter image description here

5
  • @Gonzalo Medina, it seems to me that your second solution, which uses \pgfuseplotmark, draws the marks a bit off. Is there a way to fix that? I am really interested in a way to use \pgfuseplotmark on the correct position. Note: I see that only \pgfuseplotmark has this problem, if you put a text in the node it gets centered correctly.
    – Nicola
    Oct 13, 2013 at 19:39
  • I can't comment so I comment here: @Gonzalos Medina's answer; when I do as you suggest it seems the markings (squares,circles, etc.) are off by 0.05 in the x-direction. Very strange. Nov 13, 2013 at 13:40
  • @Nicola This is now discussed at tex.stackexchange.com/q/144810/15925 Nov 13, 2013 at 14:46
  • The \pgfuseplotmark command should not be used as text! "Most, but not all, commands of the pgf package must be given within a {pgfpicture} environment." (pgf manual, v3.0, p.973) Sep 24, 2014 at 21:02
  • 1
    Isn't the circle (10px) syntax deprecated in favor of circle [radius=10px]?
    – Clément
    Jan 6, 2017 at 0:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .