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.

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"?

share|improve this question
1  
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. –  Christian Feuersänger Jul 24 '12 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. –  Peter Grill Jul 24 '12 at 20:22
add comment

1 Answer 1

up vote 23 down vote accepted

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

share|improve this answer
    
In the second and third solutions, how may I adjust the color and size of the marks? –  FEQ Jul 25 '12 at 2:17
    
@Chang please see my updated answer. –  Gonzalo Medina Jul 25 '12 at 2:27
    
Thanks a lot for your wonderful answer! –  FEQ Jul 25 '12 at 12:48
    
@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 '13 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. –  Love Learning Nov 13 '13 at 13:40
show 1 more comment

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.