0

I would like to add the line number of each line instead of the character "a" which I managed to add by tweaking the code a bit.

The code is already modified according to How to continue lines on next page in exam class \fillwithlines in order for the lines to span over multiple pages.

Here is the code at the moment:


\makeatletter
\newlength\linefillheight
\newlength\linefillthickness
\setlength\linefillheight{.25in}
\setlength\linefillthickness{0.1pt}

\newcommand{\linefill}[1]{\leavevmode
   #1 \leaders\hrule height \linefillthickness \hfill\kern\z@}


\def\fillwithlines#1{%
  \begingroup
  \ifhmode
    \par
  \fi
  \hrule height \z@
  \nobreak
  \setbox0=\hbox to \hsize{\hskip \@totalleftmargin
          \vrule height \linefillheight depth \z@ width \z@
          \linefill{a}}%
  % We use \cleaders (rather than \leaders) so that a given
  % vertical space will always produce the same number of lines
  % no matter where on the page it happens to start:
  %\cleaders \copy0 \vskip #1 \hbox{}%
    \loop\ifdim\dimen0<#1\relax
    \advance\dimen0 by \ht0
    \copy0\space
  \repeat
      \endgroup
}

\makeatother

1 Answer 1

0

Here is the code that works. I defined a counter and printed the counter before the each line incrementing it.

I also changed the code so that the fillwithlines command becomes of function of the number of lines to print and not of the vertical space of lines wanted.

\makeatletter
\newlength\linefillheight
\newlength\linefillthickness
\setlength\linefillheight{.25in}
\setlength\linefillthickness{0.1pt}

\newcommand{\linefill}{\leavevmode \leaders\hrule height \linefillthickness \hfill\kern\z@}
\newcounter{linecounter}
\setcounter{linecounter}{0}

\def\fillwithlines#1{%
  \begingroup
  \ifhmode
    \par
  \fi
  \hrule height \z@
  \nobreak
  \setbox0=\hbox to \hsize{\hskip \@totalleftmargin
          \vrule height \linefillheight depth \z@ width \z@
          \linefill}%
  % We use \cleaders (rather than \leaders) so that a given
  % vertical space will always produce the same number of lines
  % no matter where on the page it happens to start:
  %\cleaders \copy0 \vskip #1 \hbox{}%
    \loop\ifnum\thelinecounter<#1\relax
    \addtocounter{linecounter}{1}
    \thelinecounter
    \advance\dimen0 by \ht0
    \copy0\space
  \repeat
      \endgroup
}
2
  • But it is an answer, how should I do it?
    – Nre
    Commented Jan 25, 2022 at 16:59
  • @Nre: Does this answer the/your question, or was it meant as an addition to the question? (...just clarifying...)
    – Werner
    Commented Jan 25, 2022 at 18:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .