0

When using lineno for linenumbering, the following code

\documentclass{article}
\usepackage[columnwise]{lineno}
\usepackage{lipsum}
\usepackage{showframe}
\usepackage{multicol}
\usepackage{blindtext}
\usepackage{adjmulticol}
\setlength{\columnsep}{2em}

\begin{document}
\begin{multicols}{2}
    Text that exists outside of line numbering environment.
    
    \bigskip
    \begin{linenumbers}
        \blindtext

        \blindtext

        \blindtext
    \end{linenumbers}
\end{multicols}
\end{document}

adds line numbers outside of the page frame, as shown below:

Compiled code with line numbering outside of page frame within multicolumn environment

I need the line numbers to appear within the frame, to the left of the column (no switch option).

I've tried internallinenumbers, but since I'm using columns with content that will occupy both columns, an environment like parbox won't work.

I've also tried the adjmulticol package to resize the columns, but it moves the entire columns' contents over, not just the content with line numbering.

Any thoughts on a viable solution?

1 Answer 1

1

You need to do two things:

  1. Adjust the margins of the numbered text. There are a number of ways to do this, but an easy one is the addmargin environment in KOMA-Script. (See the answers to this question for other possibilities.)

  2. Adjust the \linenumbersep length to pull the numbers over to where you want.

This answer uses a KOMA-Script class, but you can also get the same function from scrextend if you need a different document class.

\documentclass{scrartcl}
\usepackage{lineno}
\usepackage{showframe}
\usepackage{multicol}
\usepackage{blindtext}
\setlength{\columnsep}{2em}
\setlength{\linenumbersep}{-14pt}

\begin{document}
\begin{multicols}{2}
    Text that exists outside of line numbering environment.

    \bigskip
    \begin{addmargin}[16pt]{0pt}
    \begin{linenumbers}
        \blindtext

        \blindtext

        \blindtext
    \end{linenumbers}
    \end{addmargin}
\end{multicols}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.