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.

Im a newbie to TikZ, so this question may seem stupid. Im a looking at a facility location problem in the plane where I have generated some data points consisting of (x,y)-coordinates for each customer node and each facility node. In the literature, customers nodes are usually marked by a circular dot so I have used the notation

\draw [fill] (x,y) circle [radius=0.05]; 

for some point specified by (x,y).

The facility nodes are usually marked with a small square. But how do I create a square centered at the point (x,y)? I have looked at rectangle function. But as I have the center point, this approach does not seem to be the right way to go. Can anyone help me here?

share|improve this question
add comment

2 Answers

For this application, I would recommend to use the \draw plot [<options>] coordinates {<coordinate list>}; functionality. If you load \usetikzlibrary{plotmarks}, you have access to a variety of different marks, including filled or empty squares, and it's really easy to provide the coordinates.

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

\begin{document}
\begin{tikzpicture}
\draw [very thin, lightgray] (0,0) grid (4,4);
\draw [cyan] plot [only marks, mark=square*] coordinates {(1,1) (2,3) (2.5,2)};
\draw [orange] plot [only marks, mark size=2.5, mark=*] coordinates {(0,0.5) (1,1.5) (1,2.5) (2,1) (4,2)};
\end{tikzpicture}
\end{document}
share|improve this answer
    
The little problem with marks, when you want to scale the picture, you scale the marks. For example if xand yare different, the marks lok not fine. It's not always desired. I don't know if it's possible to avoid this feature. It's a problem in geometry with points. It would be interesting to altern between marks and nodes or coordinates. –  Alain Matthes Jun 7 '12 at 14:31
2  
You can make the plot mark size independent of the scale by putting \makeatletter \def\pgfuseplotmark#1{\pgftransformresetnontranslations\csname pgf@plot@mark@#1\endcsname} \makeatother into your preamble. –  Jake Jun 7 '12 at 14:55
2  
Thanks very useful! Perhaps it is a good idea that I ask the question for other users. It's interesting to know this feature. –  Alain Matthes Jun 7 '12 at 15:01
add comment

To complete Jake's answer, other possibilities are :

\documentclass{article}
\usepackage{tikz}    
\begin{document}

 \begin{tikzpicture}
   \newcommand\Square[1]{+(-#1,-#1) rectangle +(#1,#1)}
   \draw [very thin, lightgray] (0,0) grid (4,4);  
     \draw (2,3) +(-2pt,-2pt) rectangle +(2pt,2pt) ;
     \draw (2,3) \Square{12pt} ;    
 \end{tikzpicture}    
\end{document}

enter image description here

You can use a node and also a coordinate like this

\begin{tikzpicture} [dot/.style={draw,rectangle,minimum size=4mm,inner sep=0pt,outer sep=0pt,thick}]
  \draw [very thin, lightgray] (0,0) grid (4,4);
  \path (1,1) coordinate[dot] ;  
\end{tikzpicture} 

enter image description here

With a node :

  \node [rectangle,minimum size=4mm,inner sep=0pt,outer sep=0pt,thick] at (1,1) {};
share|improve this answer
add 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.