我的目标是将环境中行的最后一个数字\begin{linenumbers} ... \end{linenumbers}
(本例中为 3)保存为计数器或新命令(或类似的东西)。我如何才能得到“3”?
\documentclass[11pt,german]{article}
\usepackage[T1]{fontenc}
\usepackage[sfdefault,condensed,light]{roboto}
\usepackage[utf8]{inputenc}
\newcounter{mylineno}
\newcommand{\mylineno}{}
\usepackage{lineno}
\renewcommand{\makeLineNumber}{\llap{\linenumberfont\rlap{\LineNumber}\hspace*{-5 mm}}}
\renewcommand{\linenumberfont}{\footnotesize}
%\setcounter{mylineno}{\LineNumber} <- doesnt save the counter as "3"
%\renewcommand{\mylineno}{\LineNumber} <- doesnt save the newcommand as "3"
\begin{document}
\begin{linenumbers}
\modulolinenumbers[1]
\resetlinenumber
some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text
\end{linenumbers}
\end{document}
以下是我在 PDF 文档中得到的内容:
答案1
\documentclass{article}
\usepackage{lineno}
\newcounter{lastlineno}
\def\lastlinenumber{%
\setcounter{lastlineno}{\value{linenumber}}%
\addtocounter{lastlineno}{-1}%
\thelastlineno}
\begin{document}
\begin{linenumbers}
some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text
\end{linenumbers}
\lastlinenumber
\end{document}
答案2
您可以接入该linenumbers
环境。
\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[sfdefault,condensed,light]{roboto}
\usepackage{lineno}
\AddToHook{env/linenumbers/after}{%
\xdef\thelastlineno{\the\numexpr\value{linenumber}-1\relax}%
}
\begin{document}
\begin{linenumbers}
\modulolinenumbers[1]
\resetlinenumber
some text some text some text some text some text some text
some text some text some text some text some text some text
some text some text some text some text some text some text
some text some text some text some text some text
\end{linenumbers}
The previous paragraph had \thelastlineno\ lines.
\end{document}