Graphics, Figures & Tablesputting comma makes error in pgf

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
ahmedlasheen
Posts: 43
Joined: Wed Oct 27, 2010 10:25 pm

putting comma makes error in pgf

Post by ahmedlasheen »

Hello
when i am trying to put a comma in the label coordinate of the follwing code ,i want the label be for example (2,2) but the comma give me alot of errors so i put it
(2 2).here is the code .

Code: Select all

\begin{tikzpicture}
\draw[step=1cm] (1,1) grid (4,4);
\node at ( 2,2) [circle,draw=blue!90,fill=blue!10,inner sep=0pt,minimum size=2mm,label=80:\tiny $(2 2)$] {};
\node at ( 2,3) [circle,draw=blue!90,fill=blue!10,inner sep=0pt,minimum size=2mm,label=80:\tiny $(2 2)$] {};
\node at ( 3,3) [circle,draw=blue!90,fill=blue!10,inner sep=0pt,minimum size=2mm,label=80:\tiny $(3 3)$] {};
\node at ( 3,2) [circle,draw=blue!90,fill=blue!10,inner sep=0pt,minimum size=2mm,label=80:\tiny $(3 2)$] {};

\node at ( 1,1) [circle,draw=red!90,fill=blue!10,inner sep=0pt,minimum size=2mm,label=80:\tiny $(1 1)$] {};
\node at ( 2,1) [circle,draw=red!90,fill=blue!10,inner sep=0pt,minimum size=2mm,label=80:\tiny $(2 1)$] {};
\node at ( 3,1) [circle,draw=red!90,fill=blue!10,inner sep=0pt,minimum size=2mm,label=80:\tiny $(3 1)$] {};
\node at ( 4,1) [circle,draw=red!90,fill=blue!10,inner sep=0pt,minimum size=2mm,label=80:\tiny $(4 1)$] {};
\node at ( 4,2) [circle,draw=red!90,fill=blue!10,inner sep=0pt,minimum size=2mm,label=80:\tiny $(4 2)$] {};
\node at ( 4,3) [circle,draw=red!90,fill=blue!10,inner sep=0pt,minimum size=2mm,label=80:\tiny $(4 3)$] {};
\node at ( 4,4) [circle,draw=red!90,fill=blue!10,inner sep=0pt,minimum size=2mm,label=80:\tiny $(4 4)$] {};
\node at ( 3,4) [circle,draw=red!90,fill=blue!10,inner sep=0pt,minimum size=2mm,label=80:\tiny $(3 4)$] {};
\node at ( 2,4) [circle,draw=red!90,fill=blue!10,inner sep=0pt,minimum size=2mm,label=80:\tiny $(2 4)$] {};
\node at ( 1,4) [circle,draw=red!90,fill=blue!10,inner sep=0pt,minimum size=2mm,label=80:\tiny $(1 4)$] {};
\node at ( 1,3) [circle,draw=red!90,fill=blue!10,inner sep=0pt,minimum size=2mm,label=80:\tiny $(1 3)$] {};
\node at ( 1,2) [circle,draw=red!90,fill=blue!10,inner sep=0pt,minimum size=2mm,label=80:\tiny $(1 2)$] {};
\end{tikzpicture}
\end{figure}
i have attached the log and tex and pdf files.
thanks in advance
Attachments
exp.log
(30.63 KiB) Downloaded 233 times
exp.pdf
(17.43 KiB) Downloaded 271 times
exp.tex
(2.26 KiB) Downloaded 225 times
Last edited by ahmedlasheen on Sat Mar 19, 2011 2:35 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

putting comma makes error in pgf

Post by localghost »

Please get used to always providing a complete but minimal example. Otherwise I'm pessimistic about specific help when a problem becomes more complicated. Keep that in mind for the future so that further reminders will not be necessary.

In order not to confuse pgf/tikZ you have to group the coordinates you want to print with curly braces. See example below (with some minor enhancements).

Code: Select all

\documentclass{article}
\usepackage{tikz}

\begin{document}
  \begin{tikzpicture}[%
    font=\tiny,
    every node/.style={circle,inner sep=0pt,minimum size=2mm},
    blueborder/.style={draw=blue!90,fill=blue!10},
    redborder/.style={draw=red!90,fill=red!10}
  ]
    \draw (1,1) grid (4,4);
    \foreach \x/\y in {2/2,2/3,3/2,3/3}
      \node at (\x,\y) [blueborder,label=80:{(\x,\y)}] {};
    \foreach \x/\y in {1/1,1/2,1/3,1/4,2/1,2/4,3/1,3/4,4/1,4/2,4/3,4/4}
      \node at (\x,\y) [redborder,label=80:{(\x,\y)}] {};
  \end{tikzpicture}
\end{document}

Thorsten
ahmedlasheen
Posts: 43
Joined: Wed Oct 27, 2010 10:25 pm

Re: putting comma makes error in pgf

Post by ahmedlasheen »

thanks alot, the code is working know ,and also thanks for the compact code for the grid .
Post Reply