7

I have to add line numbers to a document. It would be nice if the line numbers are also printed (and counted) inside tables. Consider the following example:

\documentclass{scrartcl}
\usepackage{blindtext}

\usepackage{lineno}
\linenumbers

\usepackage{longtable}

\begin{document}

\blindtext

\begin{longtable}{|p{\textwidth}|}
  \blindtext 
\end{longtable}

\begin{tabular}{|p{\textwidth}|}
  \blindtext 
\end{tabular}

\blindtext

\end{document}

Giving the following result:

no linenumbers next to table

The \longtable doesn't get numbers at all, the regular \tabular is considered a single line. There seems to be a longtable option to the lineno package, but this also adds just one line number to the whole table.

How do I get line numbers for each line in a longtable?

1 Answer 1

5

Using \internallinenumbers seems to work.

Update: Comment asked to change the spacing inside the new env. To use \internallinenumbers it needs a new env. One can use minipage or parbox and may be others, and it will work. To adjust the margins, here is the updated example using \vspace{5pt} but there are other ways to adjust margins and spacings one can use.

Mathematica graphics

code

\documentclass{scrartcl}
\usepackage{blindtext}

\usepackage{lineno}
\linenumbers
\usepackage{longtable}
\usepackage{calc}
\setlength{\fboxsep}{20pt}
\begin{document}

\blindtext

\begin{longtable}{|p{0.7\textwidth}|p{0.3\textwidth}|}\hline
\begin{minipage}[c]{\linewidth}
\vspace{5pt}
\internallinenumbers
\blindtext
\end{minipage}
&
This is a test

This is a test
\\\hline
\end{longtable}

\blindtext

\nolinenumbers
\begin{tabular}{|p{\textwidth}|}
\parbox[c]{\linewidth}{
\vspace{5pt}
\internallinenumbers
  \blindtext
}
\end{tabular}
\linenumbers
\blindtext
\end{document}
5
  • Don't have LaTeX at hand right now, are the minipages necessary?
    – Jasper
    May 30, 2016 at 5:24
  • @Jasper yes. Without it, it will not work.
    – Nasser
    May 30, 2016 at 5:28
  • Why is the L sticking out of the table border in line 10 (or how do you fix it)?
    – Jasper
    May 30, 2016 at 19:05
  • @Jasper you can fine tune the layout in number of way. I used vspace, but there could be other and better ways. Updated example.
    – Nasser
    May 30, 2016 at 22:08
  • Thanks, this works, but is way too ugly (speaking about the source code) for my purposes (many cells with 2 or 3 lines). I guess I'll go without line numbers then.
    – Jasper
    May 30, 2016 at 23:14

You must log in to answer this question.

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