LaTeX forum ⇒ Generallineno 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'

Postby gallioleo » Thu Nov 18, 2021 6:41 pm

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?

Thanks in advance.

Best Regards.

Recommended reading 2021:

LaTeXguide.org • LaTeX-Cookbook.net
LaTeX Beginner's Guide LaTeX Cookbook
User avatar
Ijon Tichy
Posts: 587
Joined: Mon Dec 24, 2018 10:12 am

lineno number caption w/ honor '\linenumbers'

Postby Ijon Tichy » Thu Nov 18, 2021 7:59 pm

Without Infominimal 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'

Postby gallioleo » Thu Nov 18, 2021 9:20 pm

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:
Image
Attachments
Zwischenablage01.png
Zwischenablage01.png (17.84 KiB) Viewed 932 times
Last edited by Stefan Kottwitz on Fri Nov 19, 2021 11:54 am, edited 1 time in total.
Reason: Code tags fixed

User avatar
Ijon Tichy
Posts: 587
Joined: Mon Dec 24, 2018 10:12 am

lineno number caption w/ honor '\linenumbers'

Postby Ijon Tichy » Fri Nov 19, 2021 11:34 am

Please use code tags for code. MWE tags are to be used to add a Infominimal 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}
\AddToHook{env/figure/begin}{% Needs LaTeX 2020/10/01 or newer!
  \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'

Postby gallioleo » Fri Nov 19, 2021 1:29 pm

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!

User avatar
Ijon Tichy
Posts: 587
Joined: Mon Dec 24, 2018 10:12 am

lineno number caption w/ honor '\linenumbers'

Postby Ijon Tichy » Fri Nov 19, 2021 2:06 pm

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'

Postby gallioleo » Fri Nov 19, 2021 2:31 pm

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'

Postby gallioleo » Fri Nov 19, 2021 9:33 pm

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
%   https://www1.pub.informatik.uni-wuerzburg.de/eurocg2020/data/uploads/eurocg20-submission.cls
\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}



Return to “General”

Who is online

Users browsing this forum: No registered users and 4 guests