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 have a TikZ grid

\draw[step=0.5cm,color=gray] (0,0) grid (3.5,3.5);

But I'd like to draw the grid without edges, or with half of the edges cells missing, so that it appears to be a small section of a larger, infinite grid. What's the best way to achieve this?

share|improve this question
    
BTW, maybe help lines instead of color=gray –  Leo Liu Nov 25 '11 at 19:25

5 Answers 5

up vote 22 down vote accepted

If you make the coordinates not an exact multiple of the step size you can get this effect:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
   \draw[step=0.5cm,color=gray] (.75,.75) grid (3.75,3.75);
\end{tikzpicture}
\end{document}

output of code

share|improve this answer

If you care for something a bit fancier, you could also try that one:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fadings}
\begin{document}
\begin{tikzpicture}
   \draw[step=0.5cm,color=gray,path fading=south] (.99,.75) grid (3.5,1);
   \draw[step=0.5cm,color=gray,path fading=north] (.99,3.5) grid (3.5,3.75);
   \draw[step=0.5cm,color=gray,path fading=west] (.75,.99) grid (1,3.5);
   \draw[step=0.5cm,color=gray,path fading=east] (3.5,.99) grid (3.75,3.5);
   \draw[step=0.5cm,color=gray] (1,1) grid (3.5,3.5);
\end{tikzpicture}
\end{document}

output of code

share|improve this answer
    
Possible : \begin{tikzpicture}[styling/.style={step=0.5cm,color=gray,path fading=#1}] then styling=south etc. and styling=none for the last path. –  Alain Matthes May 25 '12 at 11:18

You could draw some additional lines:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw[step=0.5cm,color=gray] (0,0) grid (3.5,3.5);
\foreach \i in {0,0.5,...,3.5}
  {
  \draw[gray] (3.5,\i) -- (3.8,\i);
  \draw[gray] (0,\i) -- (-0.3,\i);
  \draw[gray] (\i,3.5) -- (\i,3.8);
  \draw[gray] (\i,0) -- (\i,-0.3);
  }
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer

I needed the same thing, but had things in the cells of the grid, which I also wanted to fade out. This solution is perhaps less elegant than others, but permits this sort of fading.

It just puts fading rectangles over the edges so they fade out to white.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fadings}

\begin{document}
\begin{tikzpicture}
    \draw[step=0.5cm] (0.1,0.1) grid (3.9,3.9);
    % Some letters to demonstrate fading
    \node at (0.25,0.25) {F};
    \node at (0.75,0.75) {A};
    \node at (1.25,0.25) {D};
    \node at (1.75,0.75) {E};

    \begin{scope}[transparency group]
        % Left edge
        \fill[path fading=east, color=white] (0,0) rectangle (1,4);
        % Bottom edge
        \fill[path fading=north, color=white] (0,0) rectangle (4,1);
        % Right edge
        \fill[path fading=west, color=white] (3,0) rectangle (4,4);
        % Top edge
        \fill[path fading=south, color=white] (0,3) rectangle (4,4);
    \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Oooo.... this is beautiful :-) –  Richard May 25 '12 at 15:58

With PSTricks,

\documentclass{article}
\usepackage{pstricks,multido}

\begin{document}
\begin{pspicture}(-4.5,-4.5)(4.5,4.5)
\multido{\ix=-4+1}{9}
{
    \psline(\ix,4.5)(\ix,-4.5)
    \psline(4.5,\ix)(-4.5,\ix)
}
\end{pspicture}
\end{document}

enter image description here

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.