如何防止空白行被计入 Latex 中的行号?

How can I prevent blank lines from being counted in line numbers in Latex?

在我用 Latex 块引用写的诗中,我想显示行数。但是,我不希望空行算作行号。为了计算行号,我使用 Latex 中的 lineno.sty 包。如果我在空行中写 \resetlinenumber[5] 使得下一行(第二段的第一行)算作第五行,那么 latex 将第一段的第一行算作第五行,即不是我想要的。是否可以避免计算行号中的空行?

这是可编译代码块:

\documentclass[a4paper,10pt,fleqn]{report}
\usepackage[top = 1in, bottom = 1in, left = 0.8in, right = 0.8in]{geometry}
\usepackage{enumitem}
%answer lettering
\makeatletter
\newcommand*{\actenum}[1]{
    \expandafter\@actenum\csname c@#1\endcsname
}
\newcommand*{\@actenum}[1]{
    \ifcase#1\or (\textbf{A}) \or (\textbf{B}) \or (\textbf{C}) \or (\textbf{D}) \or (\textbf{E}) \else\@ctrerr\fi
}
\AddEnumerateCounter{\actenum}{\@actenum}{B}
\makeatother
\newsavebox{\fminipagebox}
\NewDocumentEnvironment{fminipage}{m O{\fboxsep}}
 {\par\kern#2\noindent\begin{lrbox}{\fminipagebox}
  \begin{minipage}{#1}\ignorespaces}
 {\end{minipage}\end{lrbox}%
  \makebox[#1]{%
    \kern\dimexpr-\fboxsep-\fboxrule\relax
    \fbox{\usebox{\fminipagebox}}%
    \kern\dimexpr-\fboxsep-\fboxrule\relax
  }\par\kern#2
 }
\newenvironment{blockquote}{%
  \par%
  \medskip
  \leftskip=4em\rightskip=2em%
  \noindent\ignorespaces}{%
  \par\medskip}
\usepackage{lineno}
\modulolinenumbers[5]

\begin{document}
\makeatother
\begin{center}
    \begin{fminipage}{6in}
        \begin{blockquote}
            \begin{internallinenumbers}
                \resetlinenumber
                Last night I heard your voice, mother,\
                The words you sang to me\
                When I, a little barefoot boy,\
                Knelt down against your knee.\
                
                And tears gushed from my heart, mother,\
                And passed beyond its wall,\
                But though the fountain reached my throat\
                The drops refused to fall.\
                
                'Tis ten years since you died, mother,\
                Just ten dark years of pain,\
                And oh, I only wish that I\
                Could weep just once again.
            \end{internallinenumbers}
        \end{blockquote}
    \end{fminipage}
\end{center}
\end{document}

这是输出:

您可以通过完全不使用空行来避免此问题:

\documentclass[a4paper,10pt,fleqn]{report}
\usepackage[top = 1in, bottom = 1in, left = 0.8in, right = 0.8in]{geometry}
\usepackage{enumitem}
%answer lettering
\makeatletter
\newcommand*{\actenum}[1]{
    \expandafter\@actenum\csname c@#1\endcsname
}
\newcommand*{\@actenum}[1]{
    \ifcase#1\or (\textbf{A}) \or (\textbf{B}) \or (\textbf{C}) \or (\textbf{D}) \or (\textbf{E}) \else\@ctrerr\fi
}
\AddEnumerateCounter{\actenum}{\@actenum}{B}
\makeatother
\newsavebox{\fminipagebox}
\NewDocumentEnvironment{fminipage}{m O{\fboxsep}}
 {\par\kern#2\noindent\begin{lrbox}{\fminipagebox}
  \begin{minipage}{#1}\ignorespaces}
 {\end{minipage}\end{lrbox}%
  \makebox[#1]{%
    \kern\dimexpr-\fboxsep-\fboxrule\relax
    \fbox{\usebox{\fminipagebox}}%
    \kern\dimexpr-\fboxsep-\fboxrule\relax
  }\par\kern#2
 }
\newenvironment{blockquote}{%
  \par%
  \medskip
  \leftskip=4em\rightskip=2em%
  \noindent\ignorespaces}{%
  \par\medskip}
\usepackage{lineno}
\modulolinenumbers[5]

\begin{document}
\makeatother
\begin{center}
    \begin{fminipage}{6in}
        \begin{blockquote}
            \begin{internallinenumbers}
                \obeylines
                \resetlinenumber
                Last night I heard your voice, mother,
                The words you sang to me
                When I, a little barefoot boy,
                Knelt down against your knee.\medskip
                
                And tears gushed from my heart, mother,
                And passed beyond its wall,
                But though the fountain reached my throat
                The drops refused to fall.\medskip
                
                'Tis ten years since you died, mother,
                Just ten dark years of pain,
                And oh, I only wish that I
                Could weep just once again.
            \end{internallinenumbers}
        \end{blockquote}
    \end{fminipage}
\end{center}
\end{document}