20

I'd like to create a page in my LaTeX document that just consists of lines. It should look like this:

enter image description here

Additionally, I want the lines numbered. I have no idea where to start. Are there any hints?

  • I'm not sure at which moment you copied my code. Please make sure you have the one that is there now. The previous version had a small bug. – yo' Oct 30 '13 at 22:35

5 Answers5

14

Two versions: \pageoflines{1cm} is without numbers; with \pageofnumberedlines you get tiny numbers in the margin.

\documentclass{article}

% to show the page frame
\usepackage{xcolor,showframe}
\renewcommand*\ShowFrameColor{\color{red}}
\renewcommand*\ShowFrameLinethickness{.2pt}
% don't show the margin par space (not needed for the macros)
\setlength{\marginparsep}{10cm}

% No numbers (easy)
\newcommand{\pageoflines}[1]{%
  \clearpage
  \begingroup\offinterlineskip
  \hrule height 0pt
  \vskip-\topskip
  \leaders\vbox to #1{\vfill\hbox to\hsize{\hrulefill}}\vfill
  \endgroup
  \clearpage}

% Numbers (a bit more difficult)
\newcommand{\pageofnumberedlines}[1]{%
  \clearpage
  \begingroup\offinterlineskip
  \count255=\vsize \dimen0=#1
  \divide\count255 by \dimen0
  \mathchardef\howmany=\count255
  \count255=0
  \loop\ifnum\count255<\howmany
    \advance\count255 by 1
    \hbox to\hsize{%
      \vrule height#1 width 0pt 
      \llap{\scriptsize\number\count255\space\space}%
      \hrulefill
    }
  \repeat
  \endgroup
  \clearpage
}

\begin{document}
\pageoflines{1cm}
\pageofnumberedlines{1cm}
\end{document}

enter image description here

egreg
  • 1,121,712
  • Now some people just like to make others feel bad :-)....... Nice contribution. Elegant. – azetina Oct 30 '13 at 23:46
  • @azetina Sorry. ;-) – egreg Oct 30 '13 at 23:47
  • 1
    But don't worry, one day, one day I will learn more and with inspiration from all of you here in TX.SX I will be able to share more elaborate and concise contributions to the OP's. :-) – azetina Oct 30 '13 at 23:50
  • can you explain how the pageoflines section does looping? I don't understand. – Tim Mar 15 '17 at 18:37
  • @Tim I compute how many rules can appear in the given text height. If a counter is set to a dimension, the dimension is coerced to the value in scaled points (65536sp=1pt). So we can do integer arithmetic. – egreg Mar 15 '17 at 18:41
  • I'm asking about the first code section, not the second . I think it's this line: \leaders\vbox to 1cm{\vfill\hbox to\hsize{\hrulefill}}\vfill but I don't understand the logic. – Tim Mar 16 '17 at 08:14
  • 1
    @Tim The leaders here are vertical leaders: stack vertically copies of the \vbox containing a rule until filling the page (\vfill). – egreg Mar 16 '17 at 11:37
11

This seems to work very well:

\documentclass{article}

\newlength{\linespagelength}
\newcounter{linespage}
\newcommand\linespage[2][0.4pt]{
  \newpage
  \begingroup
  \baselineskip0pt
  \setlength{\linespagelength}{\textheight}
  \setcounter{linespage}{0}
  \loop
  \addtolength{\linespagelength}{-#2}
  \stepcounter{linespage}
  \ifdim\linespagelength>0pt
  \vbox to #2{\vss\noindent\raise\dimexpr#1+1pt\relax\hbox to 0pt{%
    \arabic{linespage}
  \hss}\rule{\linewidth}{#1}}\nointerlineskip
  \repeat
  \endgroup
  \newpage
}

\usepackage{lipsum}

\begin{document}

\lipsum

\linespage[1pt]{1cm}

\lipsum

\end{document}

Tools:

  • \loop ... \if ... \repeat construct
  • we set \linespagelength to the \textwidth and we remove the height #2 from it at each step
  • we set the line of width #1 and the line number in a \vbox of the height #2
yo'
  • 51,322
8

A simple customizable approach with \foreach to print simple \hrules:

\documentclass[a4paper]{article}
\usepackage[margin=2.5cm]{geometry}
\usepackage{pgffor}
\pagestyle{empty}
\begin{document}
\foreach \lineas in {1, 2, ...,21}{~\hrule~\\[2em]}% 
\end{document}

MWE

Or enumerated dotted lines:

\documentclass[a4paper]{article}
\usepackage[margin=2.5cm]{geometry}
\usepackage{pgffor}
\pagestyle{empty}
\begin{document}
\begin{enumerate}
\itemsep1.1em
\foreach \puntos in {1, 2, ...,24}{\item \dotfill}%
\end{enumerate}
\end{document}

MWE

Fran
  • 80,769
7

It is only a sketch. One can change margins, vertical skips, numbering, etc.

\documentclass{article}


\def\lrule{\rule{0.95\textwidth}{0.2pt}}
\newcount\linecount
\linecount0
\def\Lrule{\advance\linecount by1\null\makebox[0.05\textwidth]{\the\linecount} \hfill\lrule\endgraf}

\pagestyle{empty}
\begin{document}

\Lrule\Lrule\Lrule\Lrule\Lrule\Lrule\Lrule\Lrule\Lrule\Lrule
\Lrule\Lrule\Lrule\Lrule\Lrule\Lrule\Lrule\Lrule\Lrule\Lrule
\Lrule\Lrule\Lrule\Lrule\Lrule\Lrule\Lrule\Lrule\Lrule\Lrule

\end{document}

enter image description here

7

Just another version using the multido package:

enter image description here

\documentclass{article}
\usepackage{multido}
\newcounter{linenum}
\renewcommand{\thelinenum}{\arabic{linenum}}
\newcommand{\numline}[1]{%
    \multido{}{#1}{%
    \refstepcounter{linenum}%
    \leavevmode\llap{\thelinenum~}\hrulefill\\[1ex]%
    }
}
\setlength{\parindent}{0pt}
\begin{document}
\numline{50}
\end{document}
azetina
  • 28,884