7

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!

14

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:

enter image description here

Even page:

enter image description here


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
\pagestyle{headings}
\blinddocument
\clearpage
\end{document}

enter image description here

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}

enter image description here

Or you can modify a predefined layer area:

\DeclareNewLayer[
  foreground,
  topmargin,
  addheight=\dimexpr\headheight+\headsep\relax,
  contents=\layercontentsmeasure
]{measurelayer}

enter image description here

9

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}

enter image description here

  • 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
7

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}

enter image description here

3

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]{%
 \AddThispageHook{\smash{\hspace*{\dimexpr-\PageLeftMargin-\hoffset+#1\relax}%
  \raisebox{\dimexpr\PageTopMargin+\voffset-#2\relax}{#3}}}}
% VERIFIED THAT SETTING \hoffset AND \voffset DO NOT BREAK SOLUTION.
%\hoffset=0.4in
%\voffset=0.2in
\begin{document}
\atxy{0in}{4in}{\includegraphics[width=30.5cm]{ruler-146428_960_720(cropped)}}
\atxy{1in}{10in}{\rotatebox{20}{%
  \includegraphics[width=30.5cm]{ruler-146428_960_720(cropped)}}}
\lipsum[1-5]
\end{document}

enter image description here

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.