## LaTeX forum ⇒ General ⇒ lineno number caption w/ honor '\linenumbers'

LaTeX specific issues not fitting into one of the other forums of this category.
gallioleo
Posts: 5
Joined: Thu Nov 18, 2021 6:35 pm

### lineno number caption w/ honor '\linenumbers'

Hello,

i like to use the lineno package to numbering my document. For numbering the caption I use the fix from 'https://tex.stackexchange.com/questions/579040/figure-caption-line-numbers-with-achemso-package?rq=1'

\usepackage{lineno}
\DeclareCaptionFont{linenumbers}{\internallinenumbers}
\captionsetup[figure]{font+=linenumbers} % use \internallinenumbers inside figure caption

This works also well, but to enable the line numbering i use the switch '\linenumbers'. With this fix the caption are always numbered w/ and w/o the line numbering enabling.

Does anyone has an idea, how i can number the caption with honoring the '\linenumbers' switch?

Best Regards.

LaTeXguide.org • LaTeX-Cookbook.net

Ijon Tichy
Posts: 590
Joined: Mon Dec 24, 2018 10:12 am

### lineno number caption w/ honor '\linenumbers'

Without minimal working example I can only speculate. Maybe:
\DeclareCaptionFont{linenumbers}{\ifLineNumbers\internallinenumbers\fi}

gallioleo
Posts: 5
Joined: Thu Nov 18, 2021 6:35 pm

### lineno number caption w/ honor '\linenumbers'

Here the MWE:

\documentclass[
pagesize=pdftex,
12pt,
DIV=14,
paper=a4,
final
]{scrreprt}

\usepackage[english]{babel}
\usepackage[hang,footnotesize,bf]{caption}
\usepackage[left, pagewise, edtable]{lineno}

% enable line numbers for caption
\DeclareCaptionFont{linenumbers}{\ifLineNumbers\internallinenumbers\fi}
\captionsetup[figure]{font+=linenumbers}

% Start Document
\begin{document}

\linenumbers

My Example text before figure

\begin{figure}[h]
\caption{MyCaption}
\end{figure}

and after figure

\end{document}

The Compile result looks like follow:
Attachments
Zwischenablage01.png (17.84 KiB) Viewed 1222 times
Last edited by Stefan Kottwitz on Fri Nov 19, 2021 11:54 am, edited 1 time in total.
Reason: Code tags fixed

Ijon Tichy
Posts: 590
Joined: Mon Dec 24, 2018 10:12 am

### lineno number caption w/ honor '\linenumbers'

Please use code tags for code. MWE tags are to be used to add a minimal working example link only!

\documentclass[
pagesize=pdftex,% Nonsense, because option pagesize with detection of backend
% is te default!
12pt,
DIV=14,
paper=a4,% This is also the default.
final
]{scrreprt}

\usepackage[english]{babel}% It would be better to set the language as global option.
\usepackage[hang,footnotesize,bf]{caption}
\usepackage[left, pagewise, edtable]{lineno}

% enable line numbers for caption
\DeclareCaptionFont{linenumbers}{\internallinenumbers}
\ifLineNumbers\captionsetup{font+=linenumbers}\fi
}

% Start Document
\begin{document}

My Example text before figure and line numbering

\begin{figure}[ht]% single option h also does work like ht
\caption{MyCaption}
\end{figure}

\linenumbers

My Example text before figure

\begin{figure}[ht]% single option h also does work like ht
\caption{MyCaption}
\end{figure}

and after figure

\end{document}

gallioleo
Posts: 5
Joined: Thu Nov 18, 2021 6:35 pm

### lineno number caption w/ honor '\linenumbers'

Thanks for the code - great work! The other comment I'll honot also.
One hint the figure caption line has the same number like the line before the caption. This happends only if i use pagewise numbering. Do you have therefore a suggestion?

Thanks a lot again!

Ijon Tichy
Posts: 590
Joined: Mon Dec 24, 2018 10:12 am

### lineno number caption w/ honor '\linenumbers'

The problem is, that figure is a floating environment. The location of floats is not known before the output routine. So it I think it could be very hard to change this. I would not expect this to work. However, you could adjust the line number using \resetlinenumber, but only if you know, where the figure is placed in the output.

I'm even surprised, that line numbering in floats does work anyway.

So, no, I cannot help in this.

gallioleo
Posts: 5
Joined: Thu Nov 18, 2021 6:35 pm

### lineno number caption w/ honor '\linenumbers'

No problem, i switch to continous numbering and then did does not happen.

gallioleo
Posts: 5
Joined: Thu Nov 18, 2021 6:35 pm

### lineno number caption w/ honor '\linenumbers'

Hi again, for the tabular environment i like to use the same hook, but at the moment i fail to get it to work. Please take a look again:

\documentclass[
12pt,
DIV=14,
main=english,
final
]{scrreprt}

\usepackage{babel}
\usepackage[hang,footnotesize,bf]{caption}
\usepackage[left, pagewise, edtable]{lineno}

% table line number moved to table and not on page margin
%   https://tex.stackexchange.com/questions/85217/linenumbers-with-lineno-edtable-breaks-inside-threeparttable-because-of-captio
\makeatletter
\newenvironment{etabular}
{\resetlinenumber[1]\let\@centercr\relax\edtable{tabular}}
{\endedtable}
\newenvironment{etabular*}
{\resetlinenumber[1]\let\@centercr\relax\edtable{tabular*}}
{\endedtable}
\makeatother

% enable line numbers for tabular
\let\linenotabular\tabular%
\let\endlinenotabular\endtabular%
\renewenvironment{tabular}{\begin{edtable}{linenotabular}}{\end{edtable}}%

% Start Document
\begin{document}

\linenumbers

My Example text before table

\begin{table}[h]
\centering
\begin{tabular}{|l|}        \hline
row1                \\ \hline
row2                \\ \hline
\end{tabular}
\end{table}

and after.

\end{document}

### Who is online

Users browsing this forum: No registered users and 5 guests