# How to draw container box in TikZ? How to get it with rounded corner?

I want to draw something like this:

This is what I am able to draw:

This is my TikZ code:

\documentclass{article}
\usepackage{verbatim}
\usepackage[active,tightpage,floats]{preview}
\setlength\PreviewBorder{30pt}%
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{figure}[ht]
\centering
\begin{tikzpicture}
\coordinate (Origin)   at (0,0);
\coordinate (XAxisMin) at (0,0);
\coordinate (XAxisMax) at (5.5,0);
\coordinate (YAxisMin) at (0,0);
\coordinate (YAxisMax) at (0,4.5);
\draw [thick, gray,-latex] (XAxisMin) -- (XAxisMax);% Draw x axis
\draw [thin, gray,-latex] (YAxisMin) -- (YAxisMax);% 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] at (0.5*\x,0.5*\y) {};
% Places a dot at those points
}
}

\end{tikzpicture}
\caption{Single tile of computation (highlighted)}
\label{figure:single}
\end{figure}
\end{document}

-

You can name the circles by putting name=circle-\x-\y in their node options, and then use the fit library to fit a rectangle node around the corner circles of your area. To get the rectangle to appear behind the circles, you can use the layering functionality of PGF:

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, fit, shapes.geometric}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\begin{document}

\begin{tikzpicture}
\coordinate (Origin)   at (0,0);
\coordinate (XAxisMin) at (0,0);
\coordinate (XAxisMax) at (5.5,0);
\coordinate (YAxisMin) at (0,0);
\coordinate (YAxisMax) at (0,4.5);
\draw [thick, gray,-latex] (XAxisMin) -- (XAxisMax);% Draw x axis
\draw [thin, gray,-latex] (YAxisMin) -- (YAxisMax);% 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 [draw, fill=cyan!25, rectangle, rounded corners, fit={(circle-1-5) (circle-10-8)}] {};
\end{pgfonlayer}
\end{tikzpicture}
\end{document}

-

Here is another solution. It has some common features with Jake's one, for example nodes have a name and the highlighted area is put in background. But, rather that exploiting the fit library, this solution uses directly the nodes' anchors. Notice that, in order to have a nice look, the nodes should have a outer sep value.

The code:

\documentclass{article}
\usepackage{verbatim}
\usepackage[active,tightpage,floats]{preview}
\setlength\PreviewBorder{30pt}%
\usepackage{tikz}
\usetikzlibrary{calc,backgrounds}

\begin{document}

\begin{figure}[ht]
\centering
\begin{tikzpicture}
\coordinate (Origin)   at (0,0);
\coordinate (XAxisMin) at (0,0);
\coordinate (XAxisMax) at (5.5,0);
\coordinate (YAxisMin) at (0,0);
\coordinate (YAxisMax) at (0,4.5);
\draw [thick, gray,-latex] (XAxisMin) -- (XAxisMax);% Draw x axis
\draw [thin, gray,-latex] (YAxisMin) -- (YAxisMax);% 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,outer sep=5pt] (\x-\y) at (0.5*\x,0.5*\y) {};
% Places a dot at those points
}
}

\begin{scope}[on background layer]
\draw[rounded corners,fill=green!50!lime!30]
(1-5.south west)rectangle(10-8.north east);
\end{scope}

\end{tikzpicture}
\caption{Single tile of computation (highlighted)}
\label{figure:single}
\end{figure}
\end{document}


The result:

-
An advantage of this solution compared with Jake is that the image can be scaled. It's difficult to scale with the fit option. But if it's not necessary to scale the picture, the first answer is fine. –  Alain Matthes Feb 6 '13 at 9:28