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 would like to build a grid such as the figure shown below where each grid point is surrounded by some of the two curves that describe below.

First curve: an outline around the point forming a drawing of the symbol plus "+". See the figure below.

Second curve: an outline around a drawing point forming the symbol minus "-". See the figure below.

Question 1: How do I build a grid like the picture where I have a command to choose which of the above curves surrounds the grid point?

Question 2: How do I assign color curves and points to the Grid?

Question 3 How to connect a point in the Grid to a point up, down, left, right or in any diagornal? See figure below.

Question 4 How to make a curve that surrounds many grids as shown below?

share|improve this question
A TikZ matrix node and some overlays should get you pretty much there. Check out the manual‌​. –  Roelof Spijker Mar 5 '12 at 12:31
Please show some attempt you've made in achieving this and specify what you're struggling with. The point of this Q&A site is to solve specific problems, not to have other people do your work. (Also note that it's not customary here to add a title, greeting or thank you line to a post body.) –  doncherry Mar 5 '12 at 14:31

1 Answer 1

As an example of how you could implement my comment. You could consider the following code.

\def\tminus{\node[minimum height=1.33cm]{\tikz\draw plot[smooth cycle, tension=0.25] coordinates{(-.5cm,-.5ex) (.5cm,-.5ex) (.5cm,.5ex) (-.5cm,.5ex)};};}
\def\tplus{\node[minimum height=1.33cm] {\tikz\draw plot[smooth cycle, tension=0.25] coordinates{(-.5ex,0) (-.5ex,-.5cm+.5ex) (-.5cm, -.5cm+.5ex) (-.5cm, -.5cm-.5ex) (-.5ex, -.5cm-.5ex) (-.5ex, -1cm) (.5ex,-1cm) (.5ex, -.5cm-.5ex) (.5cm, -.5cm-.5ex) (.5cm, -.5cm+.5ex) (.5ex, -.5cm+.5ex) (.5ex,0)};};}
  \begin{tikzpicture}[every node/.style={anchor=center, minimum height=1cm, minimum width=1cm}]
    \matrix (grid) [matrix of nodes,column sep=10pt,row sep=10pt] {
      \tplus  & \tminus & \tplus  & \tplus  & \tminus\\
      \tplus  & \tplus  & \tminus & \tplus  & \tminus\\
      \tplus  & \tplus  & \tplus  & \tminus & \tminus\\
      \tplus  & \tminus & \tminus & \tplus  & \tminus\\
      \tplus  & \tplus  & \tplus  & \tminus & \tplus\\
    \draw (grid-1-4) -- (grid-1-5);
    \draw (grid-1-4) -- (grid-2-4);
    \draw (grid-1-5) -- (grid-2-5);
    \draw (grid-2-5) -- (grid-3-5);
    \draw (grid-3-5) -- (grid-4-4);
    \draw (grid-4-4) -- (grid-4-3);
    \draw (grid-4-3) -- (grid-4-2);
    \draw (grid-4-2) -- (grid-4-1);
    \draw (grid-4-1) -- (grid-3-1);
    \draw (grid-3-1) -- (grid-3-2);
    \draw (grid-3-2) -- (grid-3-3);
    \draw ($(grid-3-3.center) + (1ex,1ex)$) -- ($(grid-2-4.center) - (1ex,1ex)$);

    \draw[rounded corners] (grid-1-1.north west) -- (grid-2-1.south west) -- (grid-2-2.south west) -- (grid-3-2.south west) -- (grid-3-2.south east) -- (grid-1-2.north east) -- cycle;

Which leads to


Note that the connecting is not entirely straightforward. The nodes have bounding boxes and if you want to get "good-looking" edges between two diagonal pluses you have to put in some manual work, like I showed in the last draw diagonal.

Furthermore drawing a curve around a set of symbols has to be done manually as well. It may be possible to automate these things, but it will certainly not be straightforward or easy.

share|improve this answer
Instead of using ($(grid-3-3.center) + (1ex,1ex)$) to get shorter lines you may define a style that uses the shorten key and apply it o the \draw command (or a higher scope) –  Tobi Mar 5 '12 at 14:17
@Tobi: it's used to get longer lines, not shorter ones. And it's not necessarily symmetrical. For instance, we might want to have better connecting vertical lines. But when we try to add a line from (4,4) to (5,4) it only needs to be made longer on one end (namely on the side of the minus). As far as I know, this isn't possible with shorten. –  Roelof Spijker Mar 5 '12 at 14:50
I musunderstood your usage, I forgot that (grid-3-3.center)≠(grid-3-3), but shorten accepts negativ values to make a line longer an for that can be used here to. It is also possible to differentiate between shorten < and shorten > to change the length different on both ends. –  Tobi Mar 5 '12 at 15:07
@Tobi: Ah, yes! I forgot about the separate > and < versions. Then it can indeed be used quite well. –  Roelof Spijker Mar 5 '12 at 15:18

Your Answer


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.