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?
\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 10487 times
Last edited by Stefan Kottwitz on Fri Nov 19, 2021 11:54 am, edited 1 time in total.
Reason:Code tags fixed
\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}
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms.
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?
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.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms.
\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}