0

I want to create a 32 by 32 grid as shown below. enter image description here

And I also want to add two labeling in x and y directions.

1) 0 - 31 (grid number)

2) 0- 1 (box unit)

I a next slide I have to draw a new box starting from grid number 8 and ends on the grid number 23.

And in the next level I have to add another box which has to start from grid number 12 and should end on grid number 19.

Is there any method to accomplish this ? I tried with TikZ

\draw and \fill

commands. But not giving any desirable result. Please suggest any method to achieve this.

Thank you.

R S John
  • 393

3 Answers3

4

Jesse's comment is probably easiest, but something along the lines of the code below works, also

\documentclass{article} 

\usepackage[margin=1in]{geometry}
\usepackage{tikz}

\begin{document}

\begin{center}
\begin{tikzpicture}[scale=0.5]
\foreach\x in {0,...,31} \draw(\x,31)--(\x,0) node[anchor=north]{\x} (31,\x)--(0,\x) node[anchor=east]{\x}; 
\end{tikzpicture}
\end{center}

\end{document}
JPi
  • 13,595
4

Here a short MWE. See the pgfmanual for descriptions. Adjust the scale-option to your needs (to get the image fit to your page-size)

\documentclass[tikz, border=5mm]{standalone}
\begin{document}
 \begin{tikzpicture}[scale=.5]
  % Grid
  \draw [step=1, dotted] (0,0) grid (31,31);

  % Grid units
  \foreach \x in {0,...,31} {
   \node [below] at (\x,0) {\x};
   \node [left]  at (0,\x) {\x};
  }

  % Box units
  \draw [<->, shorten >= .5cm, shorten <= .5cm] (0,-1.5) node {0} -- ++(31,0) node {1};
  \draw [<->, shorten >= .5cm, shorten <= .5cm] (-1.5,0) node {0} -- ++(0,31) node {1};

  % Inner rectangles
  \draw [red, ultra thick] (8,8) rectangle (23,23);
  \draw [blue, ultra thick] (12,12) rectangle (19,19);
 \end{tikzpicture}
\end{document}

Rendered image: rendered image

moospit
  • 4,456
0

Just for fun solution with PSTricks.

\documentclass[pstricks,border=15mm,12pt]{standalone}
\psset{unit=6mm,dimen=monkey,linewidth=2pt}
\begin{document}
\begin{pspicture}[showgrid](31,31)
    \psframe[linecolor=red](8,8)(23,23)
    \psframe[linecolor=blue](12,12)(19,19)
    \rput(0,-1.5){0}\rput(31,-1.5){1}\psline{<->}(1,-1.5)(30,-1.5)
    \rput(-1.5,0){0}\rput(-1.5,31){1}\psline{<->}(-1.5,1)(-1.5,30)
\end{pspicture}
\end{document}

enter image description here