\captionof 中的行号

\captionof 中的行号

我想准备一个article带有行号的类文档。调用\linenumbers函数按预期对文本中的行进行编号。但是,我还想对函数中的标题行进行编号\captionof。到目前为止,只有标题中的最后一行进行了编号。调用\internallinenumbers之前\captionof没有效果。(我猜是因为我没有浮点数。)

\documentclass[12pt,a4paper]{article}
\usepackage[a4paper,left=2.6cm, right=2.9cm, top=3.5cm, bottom=3.5cm]{geometry}
\renewcommand{\baselinestretch}{2}
\usepackage{lineno}
\usepackage{caption}
\captionsetup{justification=raggedright,singlelinecheck=false}

\begin{document}
\linenumbers
\section{Some section}
Some text

\section{Figure legends}
\captionof{figure}{This should be a figure legend occupying several lines to demonstrate the problem. I will just write some text, don't pay attention to it. It does not make much sense.}
\label{fig:myfig}
\end{document}

答案1

而不是使用\internallinenumbers \caption你必须使用它里面强制\caption参数:

\documentclass[12pt,a4paper]{article}
\usepackage[a4paper,left=2.6cm, right=2.9cm, top=3.5cm, bottom=3.5cm]{geometry}
\renewcommand{\baselinestretch}{2}
\usepackage{lineno}
\usepackage{caption}
\captionsetup{justification=raggedright,singlelinecheck=false}

\begin{document}
\linenumbers
\section{Some section}
Some text

\section{Figure legends}
\captionof{figure}[{This should be a figure legend occupying several lines to
  demonstrate the problem. I will just write some text, don't pay attention to
  it. It does not make much sense.}]{\internallinenumbers This should be a figure legend occupying several lines to demonstrate the problem. I will just write some text, don't pay attention to it. It does not make much sense.}
\label{fig:myfig}
\end{document}

在此处输入图片描述

需要重复强制参数而不\internallinenumbers使用可选参数,以避免将其写入(扩展)\internallinenumberslof用于生成图形列表的文件。

您甚至可以将\internallinenumbers自动放置到强制参数中:

\documentclass[12pt,a4paper]{article}
\usepackage[a4paper,left=2.6cm, right=2.9cm, top=3.5cm, bottom=3.5cm]{geometry}
\renewcommand{\baselinestretch}{2}
\usepackage{lineno}
\usepackage{caption}
\captionsetup{justification=raggedright,singlelinecheck=false}
\AtBeginDocument{%
  \NewCommandCopy\captioncaptionof\captionof
  \RenewDocumentCommand\captionof{mO{#3}m}{%
    \captioncaptionof{#1}[{#2}]{\internallinenumbers#3}%
  }%
}

\begin{document}
\linenumbers
\section{Some section}
Some text

\section{Figure legends}
\captionof{figure}{This should be a figure legend occupying several lines to demonstrate the problem. I will just write some text, don't pay attention to it. It does not make much sense.}
\label{fig:myfig}
\end{document}

注意:如果您将其放在框或小页面内,此建议将不起作用\captionof。在这种情况下,框/小页面将获得自己的行号。因此,您必须在框前关闭行号,然后在框后重新激活它们:

\documentclass[12pt,a4paper]{article}
\usepackage[a4paper,left=2.6cm, right=2.9cm, top=3.5cm, bottom=3.5cm]{geometry}
\renewcommand{\baselinestretch}{2}
\usepackage{lineno}
\usepackage{caption}
\captionsetup{justification=raggedright,singlelinecheck=false}
\AtBeginDocument{%
  \NewCommandCopy\captioncaptionof\captionof
  \RenewDocumentCommand\captionof{mO{#3}m}{%
    \captioncaptionof{#1}[{#2}]{\internallinenumbers#3}%
  }%
}

\begin{document}
\linenumbers
\section{Some section}
Some text

\section{Figure legends}
\nolinenumbers
\begin{minipage}{\textwidth}
\captionof{figure}{This should be a figure legend occupying several lines to demonstrate the problem. I will just write some text, don't pay attention to it. It does not make much sense.}
\label{fig:myfig}
\end{minipage}

\linenumbers
Text of next paragraph.
\end{document}

相关内容