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.

I want to draw something like this:

enter image description here

This is my code:

\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz}
%\usepackage[active,tightpage,floats]{preview}
%\setlength\PreviewBorder{30pt}%
\usetikzlibrary{calc, fit, shapes.geometric}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

%\colorlet{MAROON}{Maroon}

\begin{document}

\begin{figure}[ht]
  \centering
  \begin{tikzpicture}
    \coordinate (Origin)   at (0,0);

    \coordinate (XAxisMax) at (5.5,0);
    \coordinate (YAxisMax) at (0,4.5);

    \coordinate (Ylow) at (-0.5,0);
    \coordinate (Xlow) at (0,-0.5);
    \coordinate (XMax) at (5.5,-0.5);
    \coordinate (YMax) at (-0.5,4.5);

    \draw [thick, darkgray] (Origin) -- (XAxisMax);% Draw x axis
    \draw [thick, darkgray] (Origin) -- (YAxisMax);% Draw y axis

    \draw [thick, darkgray!40, -latex] (Xlow) -- (XMax);% Draw x axis
    \draw [thick, darkgray!40, -latex] (Ylow) -- (YMax);% Draw y axis

    \foreach \x in {1,2,...,10}{% Two indices running over each
      \foreach \y in {1,2,...,8}{% node on the grid we have drawn 
        \node[thick,draw,circle,inner sep=2pt,fill=gray!60, name=circle-\x-\y] at (0.5*\x,0.5*\y) {};
            % Places a dot at those points
      }
    }


    \begin{pgfonlayer}{background}
    \node (B) [draw, color=BrickRed, fill=red!30, rectangle, rounded corners, fit={(circle-1-1) (circle-10-1)}] {};
    \end{pgfonlayer}

    \begin{pgfonlayer}{background}
    \node (A) [draw, color=BrickRed, fill=red!30, rectangle, rounded corners, fit={(circle-1-5) (circle-10-8)}] {};
    \end{pgfonlayer}

    \node[align=center, below] at (2.75,0) {$i$};
    \node[align=center, left]  at (0,2.25) {$j$};
    \node[align=center, left]  at (-0.5,2.25) {Data\\domain};
    \node [above] at (A.north) {$k = N -1$};
    \coordinate (bb1) at (circle-10-1);
    \node [above right of = 5pt] at (bb1) {$BB1$};
  \end{tikzpicture}
  \caption{Bounding boxes for convex union of data regions}
  \label{figure:single}
\end{figure}
\end{document}

I am not put right side content properly. (for example, I have tried putting BB1, but it is not coming at proper location). And how to use different size and style of code like used here for path[k][j]?

This is my output:

enter image description here

share|improve this question
2  
Sorry, what you mean with I am not put right side content properly? Properly might assume lots of meanings... Do you want it located exactly on the right of a circle? BTW: for font styles, have a look to the font key on the pgfmanual (16.4.2 Text Parameters: Font). –  Claudio Fiandrino Feb 10 '13 at 15:56

1 Answer 1

This is a possible solution:

  • all nodes are located starting from the existent circles (however I'm almost sure this answer will not locate them in the proper [mysterious] location ;-))
  • the fonts of nodes on the right side of the circles are set in teletype by means of a style
    \tikzset{my tt/.style={
      font=\ttfamily#1},
    }

let's say customizable, with the argument (in the code will be use to set the size of the font).

The code:

\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz}
%\usepackage[active,tightpage,floats]{preview}
%\setlength\PreviewBorder{30pt}%
\usetikzlibrary{calc, fit, shapes.geometric}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}


\tikzset{my tt/.style={
  font=\ttfamily#1},
}

%\colorlet{MAROON}{Maroon}

\begin{document}

\begin{figure}[ht]
  \centering
  \begin{tikzpicture}
    \coordinate (Origin)   at (0,0);

    \coordinate (XAxisMax) at (5.5,0);
    \coordinate (YAxisMax) at (0,4.5);

    \coordinate (Ylow) at (-0.5,0);
    \coordinate (Xlow) at (0,-0.5);
    \coordinate (XMax) at (5.5,-0.5);
    \coordinate (YMax) at (-0.5,4.5);

    \draw [thick, darkgray] (Origin) -- (XAxisMax);% Draw x axis
    \draw [thick, darkgray] (Origin) -- (YAxisMax);% Draw y axis

    \draw [thick, darkgray!40, -latex] (Xlow) -- (XMax);% Draw x axis
    \draw [thick, darkgray!40, -latex] (Ylow) -- (YMax);% Draw y axis

    \foreach \x in {1,2,...,10}{% Two indices running over each
      \foreach \y in {1,2,...,8}{% node on the grid we have drawn 
        \node[thick,draw,circle,inner sep=2pt,fill=gray!60, name=\x-\y] at (0.5*\x,0.5*\y) {};
            % Places a dot at those points
      }
    }


    \begin{pgfonlayer}{background}
    \node (B) [draw, color=BrickRed, fill=red!30, rectangle, rounded corners, fit={(1-1) (10-1)}] {};
    \end{pgfonlayer}

    \begin{pgfonlayer}{background}
    \node (A) [draw, color=BrickRed, fill=red!30, rectangle, rounded corners, fit={(1-5) (10-8)}] {};
    \end{pgfonlayer}

    \node[align=center, below] at (2.75,0) {$i$};
    \node[align=center, left]  at (0,2.25) {$j$};
    \node[align=center, left]  at (-0.5,2.25) {Data\\domain};
    \node[above] at (A.north) {$k = N -1$};

    \node[right=5pt,my tt=\large] at (10-2) {BB1};
    \node[right=5pt,my tt=\scriptsize] at (10-1) {path[k][j]};

    \node[right=5pt,my tt=\scriptsize, text width=1cm] at (10-7) {path[i][j] and path[i][k]};
    \node[right=5pt,my tt=\large, anchor=south west] at (10-8) {BB0};
  \end{tikzpicture}
  \caption{Bounding boxes for convex union of data regions}
  \label{figure:single}
\end{figure}
\end{document}

The result:

enter image description here

Notice that to locate more precisely the nodes, you can play with their relative position (with the positioning library) and also with the node's anchor.

Here is a simple example:

\documentclass[tikz,border=2pt,png]{standalone}
\usetikzlibrary{positioning,shapes.misc}
\pgfdeclarelayer{back}
\pgfsetlayers{back,main}
\begin{document}
\begin{tikzpicture}
\node[draw] at (0,0) (x) {Start};
\begin{pgfonlayer}{back}
 \node[draw,cross out, blue] at (x){};
\end{pgfonlayer}

% Simple usage of <position> of=<name>
\node[right of =x] {x};
\node[right of =x, anchor=north,red] {n};
\node[right of =x, anchor=north west,red!20] {nw};
\node[right of =x, anchor=north east,red!70] {ne};
\node[right of =x, anchor=south,blue] {s};
\node[right of =x, anchor=south west,blue!20] {sw};
\node[right of =x, anchor=south east,blue!70] {se};

% Usage of <position> = <distance> of <name>
\node[left=1.5cm of x, anchor=center] {x};
\node[left=1.5cm of x, anchor=north,red] {n};
\node[left=1.5cm of x, anchor=north west,red!20] {nw};
\node[left=1.5cm of x, anchor=north east,red!70] {ne};
\node[left=1.5cm of x, anchor=south,blue] {s};
\node[left=1.5cm of x, anchor=south west,blue!20] {sw};
\node[left=1.5cm of x, anchor=south east,blue!70] {se};
\end{tikzpicture}
\end{document}

The result:

enter image description here

Refer to the pgfmanual for a complete list of anchors.

share|improve this answer

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.