4

I wish to draw below image on A4 paper with tikz.The grids should be cover all writable area.

enter image description here

I have searched it on many site but still not figure out how to do it with tikz.

  • Look at the grid operation \path . . . grid[ options ] corner . . . ;, possibly in conjunction with overlay – vaettchen Oct 4 '15 at 3:12
  • 'All writeable area' means what? I've interpreted this to mean the entire paper, but your image suggests maybe not. If you mean the whole printable area, that depends entirely on your printer and printer driver. So I've taken 'writeable' to be places a human could handwrite i.e. all over the paper. – cfr Oct 4 '15 at 3:29
  • @cfr Writable area means the valid area which will write text on. The width is the linewidth, the height should be the total lines each page.I am not sure if it's the area except the margins. – lucky1928 Oct 4 '15 at 15:03
  • @lucky1928 Well, the writeable area is the whole page if you use zero margins. \linewidth can be \paperwidth in that case. The total lines per page will vary not only between documents but within documents. You can use \textheight but some pages will have text which ends before the end of the the text block. (Unless you are doing something special such as configuring for grid typesetting, but that's complicated and cannot be completely implemented at the current time.) – cfr Oct 4 '15 at 15:12
2

You also can use pgfplots for this.

Code

\documentclass[a4paper]{article}
\usepackage[margin=1cm]{geometry}
\usepackage[svgnames]{xcolor}
\usepackage{pgfplots}


\begin{document}
\thispagestyle{empty}
\pgfplotsset{minor grid style = {dashed, Green}}
\pgfplotsset{major grid style = {solid, Green}}
    \begin{figure}\centering
        \begin{tikzpicture}[Green]
        \begin{axis}[grid = both,
                     ticks = none,
                     minor tick num = 1,
                     xmin = 0,
                     ymin = 0,
                     xmax = 17,
                     ymax = 26,
                     width = 17cm,
                     height = 26cm,
                     scale only axis]
        \end{axis}
        \end{tikzpicture}
    \end{figure}
\end{document}

enter image description here

Update

If you want a 2cm separation on grid, one thing you can do is to use ytickand xtick options, as follows:

     \begin{axis}[grid = both,
                 ticks = none,
                 minor tick num = 1,
                 xmin = 0,
                 ymin = 0,
                 xmax = 16,
                 ymax = 26,
                 xtick = {0, 2,..., 16},
                 ytick = {0, 2,..., 26},
                 width = 16cm,
                 height = 26cm,
                 scale only axis]
    \end{axis}
  • Cool, how to adjust the grid width? Is it 1cm by default? – lucky1928 Oct 4 '15 at 3:53
  • One solution is to use ytick and xtick options to define where major ticks will be into the grid (solid lines). – OSjerick Oct 4 '15 at 4:08
3

I'm sure this is a duplicate but this is quicker: http://michaelgoerz.net/notes/printable-paper-with-latex-and-tikz.html and take your pick.

Modifying Michael Goerz's grid a little, for example:

% Minor adaptions from http://michaelgoerz.net/notes/printable-paper-with-latex-and-tikz.html
\documentclass[a4paper, 10pt]{article} % for A4 size paper
\usepackage{tikz}
\begin{document}
\pagestyle{empty}
\colorlet{dlines}{green!25!black}
\colorlet{llines}{green!25!gray}
\tikzset{
  dashed lines/.style={llines, very thin, densely dashed},
  strong lines/.style={dlines, very thin},
}

\begin{tikzpicture}[remember picture, overlay]
  \draw[style=dashed lines,step=10mm] (current page.south west) grid +(210mm,297mm);
  \draw[style=strong lines,step=20mm] (current page.south west) grid +(210mm,297mm);
\end{tikzpicture}

\end{document}

greenish grid

Given the weirdness of grid, modifying it a bit more:

% Major adaptions from http://michaelgoerz.net/notes/printable-paper-with-latex-and-tikz.html
\documentclass[a4paper, 10pt]{article} % for A4 size paper
\usepackage{tikz}
\begin{document}
\pagestyle{empty}
\colorlet{dlines}{green!25!black}
\colorlet{llines}{green!25!gray}
\tikzset{
  dashed lines/.style={llines, very thin, densely dashed},
  strong lines/.style={dlines, very thin},
}

\begin{tikzpicture}[remember picture, overlay]
  \foreach \i in {5,25,...,205} \draw [strong lines] (current page.south west) ++(\i mm,8.5mm) -- ++(0,280mm);
  \foreach \i in {15,35,...,195} \draw [dashed lines] (current page.south west) ++(\i mm,8.5mm) -- ++(0,280mm);
  \foreach \i in {8.5,28.5,...,288.5} \draw [strong lines] (current page.south west) ++(5mm,\i mm) -- ++(200mm,0);
  \foreach \i in {18.5,38.5,...,278.5} \draw [dashed lines] (current page.south west) ++(5mm,\i mm) -- ++(200mm,0);
\end{tikzpicture}

\end{document}

other greenish grid

  • No, I think it's different topic. – lucky1928 Oct 4 '15 at 3:06
  • @lucky1928 How can you think it is a different topic from a question which I think is a duplicate but haven't found? – cfr Oct 4 '15 at 3:16
3

It's a math game in tikz. One more example as below:

\documentclass{article}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}
\usepackage[a4paper,margin=1cm,showframe]{geometry}
\begin{document}
  \begin{tikzpicture}[remember picture,overlay]
    \def\width{1.5cm}
    \pgfmathsetlengthmacro{\offset}{\width+0.4cm}
    \pgfmathsetlengthmacro{\rows}{floor(\textheight/\offset)-1}
    \pgfmathsetlengthmacro{\cols}{floor(\textwidth/\width)-1}
    \pgfmathsetlengthmacro{\dx}{(\textwidth-(1+\cols)*\width)/2}
    \pgfmathsetlengthmacro{\dy}{(\textheight-(1+\rows)*\offset)/2}

    \coordinate (O) at ([xshift=\dx,yshift=-\dy]current page text area.north west);

    \foreach \i in {0,1,...,\cols}{
      \foreach \j in {0,1,...,\rows} {
        \draw[blue,thick] ([xshift=\i*\width,yshift=-\j*\offset]O) rectangle ++(\width,-\width);;
        \draw[blue!40,dashed] ([xshift=\i*\width,yshift=-\width/2-\j*\offset]O) -- ++ (\width,0)
            ([xshift=\width/2+\i*\width,yshift=-\j*\offset]O) -- ++ (0,-\width);
        }
    }
\end{tikzpicture}
\end{document}

Output: enter image description here

2

You can use tikz and tikzpagenodes package.

\documentclass{article}
\usepackage{tikzpagenodes}
\begin{document}
  \begin{tikzpicture}[remember picture,overlay]
     \draw[blue,step=1cm] (current page text area.south west) grid (current page text area.north east);
     \draw[blue!50,dashed,,step=5mm] (current page text area.south west) grid (current page text area.north east);
  \end{tikzpicture}
\end{document}

enter image description here

If you want this on every page, use background package.

Besides grid option, one can also draw these manually.

\documentclass{article}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}
\usepackage[a4paper,margin=2cm,showframe]{geometry}
\begin{document}
  \begin{tikzpicture}[remember picture,overlay]
     %% Vertical lines
     \foreach \x in {0,0.1,...,1.1}{
     \draw[blue] ([xshift=\x*\textwidth]current page text area.south west) --
                 ([xshift=\x*\textwidth]current page text area.north west);
}
    \foreach \x in {0.05,0.1,...,1}{
      \draw[blue!40,dashed] ([xshift=\x*\textwidth]current page text area.south west) --
                 ([xshift=\x*\textwidth]current page text area.north west);
}

   %% horizontal lines
    \foreach \x in {0,0.1,...,1.1}{
     \draw[blue] ([yshift=\x*\textheight]current page text area.south west) --
                 ([yshift=\x*\textheight]current page text area.south east);
}
    \foreach \x in {0.05,0.1,...,1}{
      \draw[blue!40,dashed] ([yshift=\x*\textheight]current page text area.south west) --
                 ([yshift=\x*\textheight]current page text area.south east);
}

  \end{tikzpicture}
\end{document}

enter image description here

This grid will exactly occupy the writable area. Try to change the margin and see yourself. Further, the density of grid can be varied by changing the sequence in the \foreach loop.

  • Cool, it will be good answer if we can remove the partial grid on the border. – lucky1928 Oct 4 '15 at 3:18
  • @lucky1928 For that you have to adjust the step suitably. Make it an exact fraction of width and height. There is also xtep and ystep so that they can be separately controlled. – user11232 Oct 4 '15 at 3:25
  • @lucky1928 I have edited the answer with another option. – user11232 Oct 4 '15 at 4:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.