我想添加每行的行号,而不是字符“a”,我通过稍微调整代码来添加它。
代码已经根据如何在考试类 \fillwithlines 中继续下一页的行以便这些行可以跨越多页。
目前的代码如下:
\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
这是有效的代码。我定义了一个计数器,并在每行增加之前打印了计数器。
我还修改了代码,使得 fillwithlines 命令变为打印行数的函数,而不是所需行数的垂直空间的函数。
\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
}