# How to create a Lined Paper Background in LaTeX using TikZ

This tutorial is about positioning relative to page in TikZ and for motivation we have considerd the example of lined paper background. We will draw lines from the left to the right of the page and starting from the top to the bottom. At the end of this tutorial, we will be able to:

• add nodes at absolute positions of a page;
• use foreach loop for repetitive instructions;
• create lined paper PDF;

If you have any questions, remarks or suggestions, please feel free to comment below or send me a message. I will be happy to hear from you, Thanks!

## 1. Absolute Position on a Page

Absolute positioning is necessary when we would like to deal with an exact coordinates in a page. Fortunately, there is already a defined node, named $\verb|current page|$ where we can use it to access the current page. It is a rectangle node whose named $\verb|south west|$ anchor is the lower left corner of the page and whose named $\verb|north east|$ anchor is the upper right corner of the page. For more details, one can refer to Referencing the Current Page Node in TikZ & PGF manual

As $\verb|current page|$ is a node name then we can use it to define page border coordinates:

• $\verb|(current page.north west)|$: is the coordinate of the upper right corner of the page.
• $\verb|(current page.north)|$: is the coordinate of the upper corner of the page.
• $\verb|(current page.center)|$: is the coordinate of the center of the page.
• $\verb|(current page.south east)|$: is the coordinate of the lower right corner of the page.
• ... etc

The next illustration summarizes the main used coordinates of a page. However, all positions on a node apply for the current page node.

## Background Layer Option in TikZ

when we deal with absolute positioning on a page, we need this to be on a lower layer as a background of the current page. For that, it is necessary to add the following options to the $\verb|tikzpicture|$ environment: $\verb|remember picture|$ and $\verb|overlay|$.

\documentclass{article}
\usepackage{tikz}

\begin{document}
\pagestyle{empty}

\begin{tikzpicture}[remember picture,overlay]

\draw (current page.north) -- (current page.south);
\draw (current page.west) -- (current page.east);
\draw (current page.center) -- (current page.north east);
\draw (current page.north west) -- (current page.south east);

\end{tikzpicture}

\end{document}



## 2. Lined Paper Background

A lined paper background can be created by drawing a line from the left to the right. This process has to be repeated from the top to the bottom of the page with a  given spacing, for example 1cm. Basically, we need to:

• draw a line from the point at coordinate $\verb|(current page.north west)|$ to the point at coordinate $\verb|(current page.north east)|$;
• shift the above line along the y-axis by -1cm;
• repeat the process $n$ times until we fill the whole page.

## Arithmetic in tikz coordinates

To perform arithmetic in TikZ coordinates, we follow the syntax $\verb|((A)+(B))|$. This will sum x-coordinates of both points A and B and y-coordinates. This necessitates to upload the calc library at the preambul of the $\LaTeX{}$ document.

Here is a relevant example which draws a y-shifted (by -1cm) horizontal line connecting the top left and top right corners of the page:

 \draw ($(current page.north west)+(0,-1)$) -- ($(current page.north east)+(0,-1)$);


## Tikz foreach loop and coordinate computation

The above code has to be repeated, around 27 times, to fill the whole page with horziontal lines with 1cm vertical spacing. Fortunately, this can be done using $\verb|foreach|$ command. Here is a detailed post about How to use the foreach loop in LaTeX?

Here is a complete a version of the LaTeX code that generates a Lined Paper Background:

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

\begin{document}
\pagestyle{empty}

\begin{tikzpicture}[remember picture,overlay]

\foreach \i in {1,2,...,27}{
\draw[lightgray] ($(current page.north west)+(0,-\i)$) -- ($(current page.north east)+(0,-\i)$);}

\end{tikzpicture}

\end{document}



You can play with options depending on your style. For example, you can change lines color, lines style (e.g. dashed, dotted).

## 3. Landscape Lined Paper PDF

In this part, we will show how to create a landscape lined paper pdf in LaTeX using TikZ. The basic idea is to use the $\verb|landscape|$ option with the $\verb|geometry|$ package and reduce the loop from 27 lines in the portrait case to 21 as follows:

 \documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage[landscape]{geometry}

\begin{document}
\pagestyle{empty}
\begin{tikzpicture}[remember picture,overlay]

\foreach \i in {1,2,...,21}{
\draw[lightgray] ($(current page.north west)+(0,-\i)$) -- ($(current page.north east)+(0,-\i)$);}

\end{tikzpicture}

\end{document}



## 4. Lined Paper College Ruled

At this level, it is easy to create a lined paper college ruled. We will add a thick line with a red color from the point with coordinates at $\verb|(current page.north west)|$ to the point with coordinates at $\verb|(current page.south west)|$. This line is shifted along the x-axis by 4cm. The latex code is given below:

 \documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage[landscape]{geometry}

\begin{document}
\pagestyle{empty}
\begin{tikzpicture}[remember picture,overlay]

\foreach \i in {1,2,...,21}{
\draw[lightgray] ($(current page.north west)+(0,-\i)$) -- ($(current page.north east)+(0,-\i)$);}

\end{tikzpicture}

\end{document}



### This Post Has 3 Comments

1. your website is the best resource on the internet to learn TikZ quickly. thanks.

1. I am very happy that you find it useful 🙂
Thanks for the encouraging comment, I really appreciate it!

2. I am brand new to using LaTeX but it was required to learn for my new job and since I am stuck at home, I thought this would be the perfect opportunity to learn at my own pace and be ready once I am able to get back to work. Lined pages was something I have been trying to grasp using TikZ and your tutorial made it so simple. Thank you!