# Place a ruler somewhere on a page

How can I place a virtual ruler (which accurately measures distance) on a page, irrespective of page margins? For example, along the left-hand side of the page from the top to the bottom.

Basically, I'm trying to find a LaTeX equivalent of making a custom document class, printing out a Lorem Ipsum version of that document, and measuring the margins by hand. I've seen this post showing how to make a ruler in TikZ, but I don't know how to 1) change the length of the ruler easily (e.g., \ruler{10}{in} for a 10" ruler) and, more importantly, 2) place the ruler on the page so I can measure page margins.

Thanks to anyone who can give an answer or help point me in the right direction!

Maybe package layout will help. It provides the command \layout which inserts one (onesided document) or two (twosided documents) pages that show the relevant sizes of the current page layout.

\documentclass{book}
\usepackage{geometry}% needed if the format of the document differs from the settings of your TeX system
\usepackage{layout}
\begin{document}
\layout
\end{document}


Odd page:

Even page:

Or you can use package scrlayer. Then you can define a new page style using a layer with contents=\layercontentsmeasure.

\documentclass[a4paper]{book}
%\usepackage{geometry}
\usepackage{blindtext}

\usepackage{scrlayer}
\DeclareNewLayer[
foreground,
innermargin,
contents=\layercontentsmeasure
]{measurelayer}
\DeclareNewPageStyleByLayers{measurestyle}{measurelayer}

\begin{document}
\chapter{A Chapter}
\Blindtext
\pagestyle{measurestyle}
\clearpage
\Blindtext
\clearpage
\blinddocument
\clearpage
\end{document}


There are other predefined layer areas like topmargin, head, headsep, textarea,... But you can also define the size and the position of a layer:

\DeclareNewLayer[
foreground,
hoffset=1cm,
voffset=.5cm,
width=2cm,
height=10cm,
contents=\layercontentsmeasure
]{measurelayer}


Or you can modify a predefined layer area:

\DeclareNewLayer[
foreground,
topmargin,
contents=\layercontentsmeasure
]{measurelayer}


Instead of a ruler you could put a grid behind the text with eso-pic package:

\documentclass{article}
\usepackage[grid,
gridcolor=red!20,
subgridcolor=green!20,
gridunit=in]{eso-pic}
\usepackage{lipsum}

\begin{document}
\lipsum
\end{document}


• Attention, copy-paste programmers like myself: One of the parameters says gridunit=in, that's why the numbers are so strange. – AndreKR Jun 12 at 18:14

There is a new package for this aim, namely fgruler:

http://www.ctan.org/pkg/fgruler

For example, try the following simple code:

\documentclass{article}
\usepackage[type=none]{fgruler}
\begin{document}
\fgruler{upperleft}{1cm}{2cm}
text
\ruler{rightup}{3cm}
text
\end{document}


I use my answer at What are the ways to position things absolutely on the page? to put something anywhere on the page. Then, I go to the web and find a nice transparent ruler, for example, at https://pixabay.com/static/uploads/photo/2013/07/12/12/52/ruler-146428_960_720.png. Then I crop it to 30.5 virtual centimeters width. Finally, I \includegraphics[width=30.5cm]{} it with my \atxy macro to overlay it anywhere on the page. Because of its transparancy, one can take measurements of what lies underneath.

\documentclass{article}
\usepackage{everypage}
\usepackage{graphicx}
\usepackage{lipsum}
% THESE ARE LaTeX DEFAULTS; CAN CHANGE IF NEEDED.
\def\PageTopMargin{1in}
\def\PageLeftMargin{1in}
\newcommand\atxy[3]{%