usepackage[modulo]{lineno} - 還需要第 1 行的行號

usepackage[modulo]{lineno} - 還需要第 1 行的行號

顯然,我使用 lineno 來對我的行進行編號。

我需要每 5 行一個數字,所以我啟用了該選項取模

但是因為1 模 5 <> 0,第一行沒有編號。正如你現在已經猜到的,我需要那個數字 1......

如果這是不可能的,我可以輕鬆地使用另一個包萊諾

螢幕截圖

MWE 的螢幕截圖

微量元素

\documentclass[]{article}

\usepackage[modulo]{lineno} 
\usepackage[parfill]{parskip}

\begin{document}

    \begin{linenumbers} 
        \textbf{Oh lord, won't you give me, my linenumber 1\\}
        Lorem ipsum dolor sit amet, consectetur adipiscing elit.\\
        Donec sit amet diam vel sapien commodo tempor at at sem.\\
        Praesent mollis enim mauris. Integer eu consequat neque.\\
        Nullam hendrerit laoreet fringilla.\\
        Aenean massa dolor, tristique maximus aliquet vel, hendrerit non mi.\\
        Pellentesque euismod mattis lectus, vel pretium turpis condimentum efficitur.\\
        Ut commodo ante nec risus sagittis, vitae sodales massa dictum.\\
        Quisque scelerisque pretium faucibus.\\
        Duis gravida ex lorem, et tincidunt diam mattis quis.\\
        Aenean nibh elit, pretium id leo ornare, congue mollis est.\\
        Etiam dictum viverra libero in imperdiet.\\
        Integer vel scelerisque urna, et porttitor turpis.\\
        Mauris porta molestie tincidunt. Vivamus ut rutrum urna.
        Lorem ipsum dolor sit amet, consectetur adipiscing elit.\\
        Donec sit amet diam vel sapien commodo tempor at at sem.\\
    \end{linenumbers}

\end{document}

答案1

如果該行是第一行,則重新定義\themodulolinenumber無條件列印數字。您必須重申您想要每五行編號一次,以便考慮重新定義。

\documentclass[]{article}

\usepackage[modulo]{lineno} 
\usepackage[parfill]{parskip}
\usepackage{etoolbox}

\patchcmd\themodulolinenumber
 {\relax}
 {\relax\ifnum\value{linenumber}=1 \thelinenumber\else}
 {}{}
\appto\themodulolinenumber{\fi}

\modulolinenumbers

\begin{document}

\begin{linenumbers} 
\textbf{Oh lord, won't you give me, my linenumber 1\\}
Lorem ipsum dolor sit amet, consectetur adipiscing elit.\\
Donec sit amet diam vel sapien commodo tempor at at sem.\\
Praesent mollis enim mauris. Integer eu consequat neque.\\
Nullam hendrerit laoreet fringilla.\\
Aenean massa dolor, tristique maximus aliquet vel, hendrerit non mi.\\
Pellentesque euismod mattis lectus, vel pretium turpis condimentum efficitur.\\
Ut commodo ante nec risus sagittis, vitae sodales massa dictum.\\
Quisque scelerisque pretium faucibus.\\
Duis gravida ex lorem, et tincidunt diam mattis quis.\\
Aenean nibh elit, pretium id leo ornare, congue mollis est.\\
Etiam dictum viverra libero in imperdiet.\\
Integer vel scelerisque urna, et porttitor turpis.\\
Mauris porta molestie tincidunt. Vivamus ut rutrum urna.
Lorem ipsum dolor sit amet, consectetur adipiscing elit.\\
Donec sit amet diam vel sapien commodo tempor at at sem.
\end{linenumbers}

\end{document}

在此輸入影像描述

相關內容