7

I would like to create the following image in TikZ for my latex file. Can you give me an idea of how to do it? Thanks.

enter image description here

I have the following so far, which is very simple:

\begin{tikzpicture}
  \draw[step=5mm,gray,very thin] (0,0) grid (7.5,7.5);
  \draw[step=25mm,black,semithick] (0,0) grid (7.5,7.5);
\end{tikzpicture}

This creates the fine 15x15 grid and the coarse 3x3 grid.

2
  • Welcome to TeX SE! Have you tried anything on your own? We are really not aware of your experience with LaTeX in general and Tikz in particular.
    – Alenanno
    Sep 29, 2016 at 11:26
  • 3
    so you also know how to draw the blue grid as well (look at the dashed option). For red dots, nodes might be indicated (\node at (<x>,<y>) {$\bullet$};). Tips: use a \foreach structure for lighter syntax. Labels can be drawn using anchor and for rectangles it's super easy : \fill (<x1>,<y1>) rectangle (<x2>,<y2>);. Finally think at the order you follow to draw the elements -- i.e. start with rectangles, so that they are in the background.
    – ebosi
    Sep 29, 2016 at 11:38

2 Answers 2

9

Here you go, the coding is not pretty but it works.

\documentclass[]{article}

\usepackage{tikz}
\usepackage{bm}
\begin{document}

\begin{tikzpicture}
  \draw[step=5mm,gray,very thin] (0,0) grid (7.5,7.5);
  \draw[step=25mm,black,semithick] (0,0) grid (7.5,7.5);


  \fill[green!50!black,opacity=0.3] (0,7.5) rectangle (2.5,5);

  \fill[orange!60!black,opacity=0.3] (3.5,1) rectangle (6.5,4.0);
  \draw[dashed,blue!50!white,very thick] (0,1.25)-- (7.5,1.25);
  \draw[dashed,blue!50!white,very thick] (0,3.75)-- (7.5,3.75);
  \draw[dashed,blue!50!white,very thick] (0,6.25)-- (7.5,6.25);

  \draw[dashed,blue!50!white,very thick] (6.25,0)-- (6.25,7.5);
  \draw[dashed,blue!50!white,very thick] (3.75,0)-- (3.75,7.5);
  \draw[dashed,blue!50!white,very thick] (1.25,0)-- (1.25,7.5);

  \fill[red!80!black] (1.25,1.25) circle (4pt);
  \fill[red!80!black] (3.75,1.25) circle (4pt);
  \fill[red!80!black] (6.25,1.25) circle (4pt);

  \fill[red!80!black] (1.25,3.75) circle (4pt);
  \fill[red!80!black] (3.75,3.75) circle (4pt);
  \fill[red!80!black] (6.25,3.75) circle (4pt);

  \fill[red!80!black] (1.25,6.25) circle (4pt);
  \fill[red!80!black] (3.75,6.25) circle (4pt);
  \fill[red!80!black] (6.25,6.25) circle (4pt);

  \draw (1.75,6.75) node {$\bm{\Omega}^C$};
  \draw (5.75,3.25) node {$\bm{\Omega}^D$};

\end{tikzpicture}

\end{document}

Result:

enter image description here

A version using \foreach:

\documentclass{article}    
\usepackage{tikz}
\usepackage{bm}
\begin{document}
\begin{tikzpicture}
  \draw[step=5mm,gray,very thin] (0,0) grid (7.5,7.5);
  \draw[step=25mm,black,semithick] (0,0) grid (7.5,7.5);    

  \fill[green!50!black,opacity=0.3] (0,7.5) rectangle (2.5,5);
  \fill[orange!60!black,opacity=0.3] (3.5,1) rectangle (6.5,4.0);

  \foreach \x in {1.25,3.75,6.25} {
     \draw[dashed,blue!50!white,very thick] (0,\x)-- (7.5,\x);
     \draw[dashed,blue!50!white,very thick] (\x,0)-- (\x,7.5);
     \foreach \y in {1.25,3.75,6.25} {
          \fill[red!80!black] (\x,\y) circle (4pt);
     }
  }
  \draw (1.75,6.75) node {$\bm{\Omega}^C$};
  \draw (5.75,3.25) node {$\bm{\Omega}^D$};

\end{tikzpicture}

\end{document}
2
  • 1
    Oh i put the omegaC in the wrong place, i'll just edit that.
    – Josh
    Sep 29, 2016 at 11:47
  • Thanks. Also, I did a slight variation to generate the dashed blue lines with \draw[step=25mm,blue,thin,dashed,xshift=12.5mm,yshift=12.5mm] (-1.25,-1.25) grid (6.25,6.25);
    – Michael
    Sep 29, 2016 at 11:56
13

Here is thus a detailed answer (I copied the color references from Josh's answer), as suggested in my comment.

Note :

  • The use of the shift option, for the blue dashed grid,
  • The use of two nested \foreach loops, for drawing the nodes.
  • The use of "round" coordinates (in order to have lighter, and more understandable code). If you need your picture to have specific dimensions, you can write add scale= xx as a global option (\begin{tikzpicture}[scale=0.1] so that 1 unit = 1mm)

Here is the MWE

\documentclass{standalone}
    \usepackage{tikz}
    \usepackage{xcolor}

\begin{document}
\begin{tikzpicture}
    \fill [green!50!black,opacity=0.3] (0,10) rectangle +(5,5);
    \fill [orange!60!black,opacity=0.3] (7,2) rectangle +(6,6);
    \draw [gray, thin, step = 1] (0,0) grid +(15,15);
    \draw [black, thick, step = 5] (0,0) grid +(15,15);
    \draw [blue, dashed, step = 5, shift = {(2.5,2.5)}] (-2.5,-2.5) grid +(15,15);
    \foreach \x in {2.5,7.5,12.5} {
        \foreach \y in {2.5,7.5,12.5} {
            \node [text=red] at (\x,\y) {$\bullet$};
        }
    }
    \node at (2.5,12.5) [above right] {$\Omega^C$};
    \node at (12.5,7.5) [below left] {$\Omega^C$};
\end{tikzpicture}
\end{document}

And the output:
enter image description here

1
  • Nice! Much more elegant sir.
    – Josh
    Sep 29, 2016 at 11:56

You must log in to answer this question.

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