0

I am using the following code :

   \documentclass[11pt]{amsart}
   \setlength{\textheight}{23cm}
    \setlength{\textwidth}{16cm}
     \setlength{\topmargin}{-0.8cm}
     \setlength{\parskip}{0.3\baselineskip}
     \hoffset=-1.4cm
     \usepackage{amsmath,amscd,amssymb}
     \usepackage{hyperref}
      \usepackage[running, pagewise]{lineno}
      \linenumbers
      \newtheorem{theorem}{Theorem}[section]
      \newtheorem{conjecture}[subsection]{Conjecture}
      \newtheorem{lemma}[theorem]{Lemma}
      \newtheorem{proposition}[theorem]{Proposition}
      \newtheorem{remark}[theorem]{Remark}
      \numberwithin{equation}{section}
      \newtheorem{definition}[theorem]{Definition}
      \newtheorem{example}[theorem]{Example}
       \newtheorem{corollary}[theorem]{Corollary}
       \renewcommand{\thefootnote}{\arabic{footnote}}
     \input xy
    \xyoption{all}
     \begin{document}
     la la la \\
    \begin{theorem}
    If this is true, then that is true.\
    \end{theorem}
    \begin{proof}
    It's always true
    \end{proof}
    la la la 
    \end{document}

before \begin{document} and the output that is coming using lineno package is discrete lining. I want line numbers (in the left) for all lines (including the gaps between the paragraphs). Please let me know if there is a way around this.

The output is as follows :enter image description here

I want that there should be line numbers between lines 2, 3 and 3,4 and 4,5 and each line after 5 where there is nothing written. Is there way to make it densely numbered? This is the journal typesetting format. Since the paper is long it will be useful for me to have the line numbers similar to the journals style in the framework of my code or some other code (which do not hamper the compilation)

3
  • 2
    numbering the variable size stretchy spaces beween items would sem a bit odd, I don't think the lineno package can do that. Someone might attempt a solution anyway, it would be helpful if you provided an example document. Currently you just show some possibly urelated theorem definitions and an unrelated (non latex syntax) loading of the xy package, but no actual test documnt showing where you want the line numbers to change. Mar 19, 2022 at 16:12
  • Many conferences and journals where you can submit papers for review just put a sequence of constant distance line numbers in the margin. This is often inprecise because the line number falls in between two lines, but for purposes of labelling a review comment this is usually adequate and it is a simpler solution than trying to number actual lines. Maybe that could be a solution here as well?
    – Marijn
    Mar 19, 2022 at 16:22
  • @DavidCarlisle, I have edited the post now.
    – HARRY
    Mar 19, 2022 at 17:20

1 Answer 1

4

As an example of my comment under the question: the Association for Computing Machinery uses continuous line numbering for papers under review. These line numbers are not linked to the actual lines in the paper and may therefore be misaligned vertically.

In the code below I added the relevant parts from acmart.cls into the example document from the question. Basically a box with line numbers is constructed by repeatedly adding the next number until the box reached \textheight. Then this box is added to the page at the top left corner using \put. This is repeated for each page by adding the \put command in a header specification using \fancyhdr.

MWE:

\documentclass[11pt]{amsart}
\usepackage{xcolor}
\setlength{\textheight}{23cm}
\setlength{\textwidth}{16cm}
\setlength{\topmargin}{-0.8cm}
\setlength{\parskip}{0.3\baselineskip}
\hoffset=-1.4cm
\usepackage{amsmath,amscd,amssymb}
\usepackage{hyperref}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{conjecture}[subsection]{Conjecture}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{remark}[theorem]{Remark}
\numberwithin{equation}{section}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\newtheorem{corollary}[theorem]{Corollary}
\renewcommand{\thefootnote}{\arabic{footnote}}
\input xy
\xyoption{all}
\usepackage{fancyhdr}
\makeatletter
% the code below is modified from acmart.cls
% source: https://ctan.org/pkg/acmart
% licensed under LPPL 1.3
\newsavebox{\ACM@linecount@bx}
\newlength\ACM@linecount@bxht
\newcount\ACM@linecount
\ACM@linecount\@ne\relax
\def\ACM@mk@linecount{%
    \savebox{\ACM@linecount@bx}[4em][t]{\parbox[t]{4em}{\normalfont
        \normalsize
        \setlength{\ACM@linecount@bxht}{0pt}%
        \loop{\color{red}\scriptsize\the\ACM@linecount}\\
        \global\advance\ACM@linecount by \@ne
        \addtolength{\ACM@linecount@bxht}{\baselineskip}%
        \ifdim\ACM@linecount@bxht<\textheight\repeat
        {\color{red}\scriptsize\the\ACM@linecount}\hfill
        \global\advance\ACM@linecount by \@ne}}}
\def\ACM@linecountL{%
  \ACM@mk@linecount
  \begin{picture}(0,0)%
    \put(-26,-18){\usebox{\ACM@linecount@bx}}%
  \end{picture}%
}
\pagestyle{fancy}
\fancyhead[L]{\ACM@linecountL}
% end of code modified from acmart.cls
\renewcommand{\headrulewidth}{0pt}
\fancypagestyle{plain}{}
\makeatother
\begin{document}
la la la \\
\begin{theorem}
If this is true, then that is true.\
\end{theorem}
\begin{proof}
It's always true
\end{proof}
la la la 
\end{document}

Result:

enter image description here


There are various parameters to modify.

  • Start the numbers before the first line: adjust \put(x,y). In the code below \put(-26,-10) puts the number 1 above the first line.
  • Number range: this is determined by the total height of the box. The code does not use the real height, instead it is simulated by the length variable \ACM@linecount@bxht which is initialized to 0pt at the start of the box and increased by \baselineskip after every number. By reducing the simulated increase you can fit more numbers before the box reaches \textheight. Trial and error leads to 0.855\baselineskip for numbers 1-60.
  • Distance between numbers: this can be set by adding a length to the linebreak \\ after each number. Trial and error leads to \\[-1.5pt] to put the number 60 near the bottom of the page.
  • Resetting the numbers each page: this can be done by putting the number counter initialization \ACM@linecount\@ne\relax inside of the macro that is called for each page header (\ACM@mk@linecount, mk means 'make').
  • Line numbers on first page: the numbers are produced by a header. This header is only shown if \pagestyle{fancy} is in effect. Many documentclasses set \pagestyle{plain} for the first page and/or for the full document. You can redefine plain to use the fancy definitions (i.e., print the header and therefore the line numbers) using \fancypagestyle{plain}{} (note: this was already included in the first version of the answer above). It is also possible that a documentclass sets the page style to empty in which case you should modify the header settings accordingly.

Modified code:

\documentclass[11pt]{amsart}
\usepackage{xcolor}
\setlength{\textheight}{23cm}
\setlength{\textwidth}{16cm}
\setlength{\topmargin}{-0.8cm}
\setlength{\parskip}{0.3\baselineskip}
\hoffset=-1.4cm
\usepackage{amsmath,amscd,amssymb}
\usepackage{hyperref}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{conjecture}[subsection]{Conjecture}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{remark}[theorem]{Remark}
\numberwithin{equation}{section}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\newtheorem{corollary}[theorem]{Corollary}
\renewcommand{\thefootnote}{\arabic{footnote}}
\input xy
\xyoption{all}
\usepackage{fancyhdr}
\usepackage{lipsum}
\makeatletter
% the code below is modified from acmart.cls
% source: https://ctan.org/pkg/acmart
% licensed under LPPL 1.3
\newsavebox{\ACM@linecount@bx}
\newlength\ACM@linecount@bxht
\newcount\ACM@linecount
%\ACM@linecount\@ne\relax
\def\ACM@mk@linecount{%
    \ACM@linecount\@ne\relax % reset counter each page
    \savebox{\ACM@linecount@bx}[4em][t]{\parbox[t]{4em}{\normalfont
        \normalsize
        \setlength{\ACM@linecount@bxht}{0pt}%
        \loop{\color{red}\scriptsize\the\ACM@linecount}\\[-1.5pt] % vertical distance between numbers
        \global\advance\ACM@linecount by \@ne
        \addtolength{\ACM@linecount@bxht}{0.855\baselineskip}% reduce similated box height increase
        \ifdim\ACM@linecount@bxht<\textheight\repeat
        {\color{red}\scriptsize\the\ACM@linecount}\hfill
        \global\advance\ACM@linecount by \@ne}}}
\def\ACM@linecountL{%
  \ACM@mk@linecount
  \begin{picture}(0,0)%
    \put(-26,-10){\usebox{\ACM@linecount@bx}}% x,y coordinates of line number 1
  \end{picture}%
}
\pagestyle{fancy}
\fancyhead[L]{\ACM@linecountL}
% end of code modified from acmart.cls
\renewcommand{\headrulewidth}{0pt}
\fancypagestyle{plain}{} % add numbers to plain pages (e.g., first page)
\makeatother
\begin{document}
la la la \\
\begin{theorem}
If this is true, then that is true.\
\end{theorem}
\begin{proof}
It's always true
\end{proof}
la la la 
\lipsum[1-8]
\end{document}

Result (end of page 1 and start of page 2):

enter image description here

7
  • thanks for the answer. Could you please kindly indicate which part of this code I should change in order to change the following : ( i) I want line numbers from 1 to 60 in a page ( ii) the line number 1 should start earlier than the actual first line of the paper and ( iii) line numbering is a littlebit dense( i.e there should be a bit less gap between line numbers n and n+1 compared to what is demonstrated here)?
    – HARRY
    Mar 20, 2022 at 3:36
  • In th output of the above code two things are occuring : (i) There is no line numbering in the first page of the manuscript (ii) In each page line numbers are increasing (is there a way to make line numbers in each page from 1 to 60)?
    – HARRY
    Mar 20, 2022 at 5:47
  • 1
    @HARRY I added some modifications to the answer.
    – Marijn
    Mar 20, 2022 at 9:26
  • thank you very much for the answer. I have one finally question : The ith line number of the output when this code is turned out to be same as i+1 th line in my journal manuscript. For example 34th line number of this output pdf matches with 35th line number of the journal manuscript. Is there a way to change the code so that every line number gets increased by exactly $1$ ?
    – HARRY
    Mar 20, 2022 at 10:57
  • You can advance the counter immediately after (re)setting it, i.e., \global\advance\ACM@linecount by \@ne following the line I marked with % reset counter each page. But then it starts at 2 and runs until 61, is that what you want?
    – Marijn
    Mar 20, 2022 at 12:32

You must log in to answer this question.

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