I wish to draw below image on A4 paper with tikz.The grids should be cover all writable area.
I have searched it on many site but still not figure out how to do it with tikz.
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityI wish to draw below image on A4 paper with tikz.The grids should be cover all writable area.
I have searched it on many site but still not figure out how to do it with tikz.
You also can use pgfplots
for this.
\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}
If you want a 2cm separation on grid, one thing you can do is to use ytick
and 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}
ytick
and xtick
options to define where major ticks will be into the grid (solid lines).
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}
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}
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}
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}
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}
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.
step
suitably. Make it an exact fraction of width and height. There is also xtep
and ystep
so that they can be separately controlled.
\path . . . grid[ options ] corner . . . ;
, possibly in conjunction withoverlay
\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.)