我正在使用软件包\ContinuedFloat
的命令subfig
将一系列图表打印到多页中。我希望在图表列表中添加一个标题,并“压缩”页面,以便只显示第一页和最后一页。
编辑:因为我也在使用该cleveref
软件包,所以我想为这两个页面添加一个链接。因此应该是 2 --> 链接到第 2 页,3 --> 链接到第 3 页,连字符是“中性”符号。
例如我现在得到的是:
图片列表
- 需要两页才能得出结果。(续)2
- 需要两页的结果 3
而我希望拥有:
图片列表
- 需要两页的结果 2-3
以下是 MWE:
\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}
\begin{document}
\listoffigures
\clearpage
\begin{figure}
\centering
\subfloat[][]{\includegraphics[scale=.9]{fig1}}
\\
\subfloat[][]{\includegraphics[scale=.9]{fig2}}
\caption{A result that requires two pages. \emph{(cont.)}}
\end{figure}
\begin{figure}
\ContinuedFloat
\centering
\subfloat[][]{\includegraphics[scale=.9]{fig3}}
\\
\subfloat[][]{\includegraphics[scale=.9]{fig4}}
\caption{A result that requires two pages.}
\end{figure}
\end{document}
答案1
只需\caption
在延续中使用一个空的可选参数(\caption
如果您想摆脱图形列表中的“(cont)”,则在第一个中使用可选参数):
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{subfig}
\begin{document}
\listoffigures
\begin{figure}[!ht]
\centering
\subfloat[][]{\includegraphics[height=1cm]{fig1}}
\\
\subfloat[][]{\includegraphics[height=1cm]{fig2}}
\caption[A result that requires two pages.]{A result that requires two pages. \emph{(cont.)}}
\end{figure}
\begin{figure}
\ContinuedFloat
\centering
\subfloat[][]{\includegraphics[height=1cm]{fig3}}
\\
\subfloat[][]{\includegraphics[height=1cm]{fig4}}
\caption[]{A result that requires two pages.}
\end{figure}
\end{document}
我改变了一些设置,以便示例能够只容纳一页。
我最初没有看到有关 LoF 中的页码编号的要求;现在有一个解决方案:
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subfig}
\def\myaddcontentsline#1#2#3{%
\addtocontents{#1}{\protect\contentsline{#2}{#3}{\thepage--\finalpage}}}
\gdef\finalatpage#1{\global\def\finalpage{#1}}
\finalatpage{0}
\makeatletter
\newcommand\MyCaption[1]{%
\myaddcontentsline{lof}{figure}{\protect\numberline{\thefigure}#1}}
\newcommand\savefinalpage{\makeatletter
\write\@auxout{\protect\finalatpage{\arabic{page}}}
\makeatother}
\makeatother
\begin{document}
\listoffigures
\clearpage
\begin{figure}
\captionsetup{list=no}
\centering
\subfloat[][]{\includegraphics[height=1cm]{fig1}}\\
\subfloat[][]{\includegraphics[height=1cm]{fig2}}
\caption{A result that requires two pages. \emph{(cont.)}}
\MyCaption{A result that requires two pages}
\end{figure}
\clearpage\mbox{}\clearpage
\begin{figure}
\captionsetup{list=no}
\ContinuedFloat
\centering
\subfloat[][]{\includegraphics[height=1cm]{fig3}}\\
\subfloat[][]{\includegraphics[height=1cm]{fig4}}
\caption{A result that requires two pages.}
\savefinalpage
\end{figure}
\end{document}
现在另一个版本有新的要求;特别是,它需要加载hyperref
:
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subfig}
\usepackage[linktocpage,colorlinks=true]{hyperref}
\makeatletter
\def\myaddcontentsline#1#2#3{%
\addtocontents{#1}{\protect\contentsline{#2}{#3}%
{\protect\hyperlink{xyzs}{\thepage}--\protect\hyperlink{xyzf}{\finalpage}}{}}%
}%
\gdef\finalatpage#1{\gdef\finalpage{#1}}
\finalatpage{0}
\def\MyCaption#1{\hypertarget{xyzs}{}%
\myaddcontentsline{lof}{figure}{\protect\numberline{\thefigure}#1}%
}
\def\savefinalpage{\hypertarget{xyzf}{}\makeatletter
\write\@auxout{\protect\finalatpage{\arabic{page}}}
\makeatother
}
\makeatother
\begin{document}
\listoffigures
\clearpage
\begin{figure}
\captionsetup{list=no}
\centering
\subfloat[][]{\includegraphics[height=1cm]{fig1}}\\
\subfloat[][]{\includegraphics[height=1cm]{fig2}}
\caption{A result that requires two pages. \emph{(cont.)}}
\MyCaption{A result that requires two pages}
\end{figure}
\clearpage\mbox{}\clearpage
\begin{figure}
\captionsetup{list=no}
\ContinuedFloat
\centering
\subfloat[][]{\includegraphics[height=1cm]{fig3}}\\
\subfloat[][]{\includegraphics[height=1cm]{fig4}}
\caption{A result that requires two pages.}
\savefinalpage
\end{figure}
\end{document}
新版本改进了后续超链接的锚定:
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subfig}
\usepackage[linktocpage,colorlinks=true]{hyperref}
\makeatletter
\def\myaddcontentsline#1#2#3{%
\addtocontents{#1}{\protect\contentsline{#2}{\ignorespaces #3}%
{\protect\hyperlink{xyzs}{\thepage}--\protect\hyperlink{xyzf}{\finalpage}}{}}%
}%
\gdef\finalatpage#1{\gdef\finalpage{#1}}
\finalatpage{0}
\def\MyCaption#1{\hypertarget{xyzs}{}%
\myaddcontentsline{lof}{figure}{\protect\numberline{\thefigure}#1}%
}
\def\savefinalpage{\makeatletter
\write\@auxout{\protect\finalatpage{\arabic{page}}}
\makeatother
}
\def\MyCaptionE#1{\caption[#1]{\hypertarget{xyzf}{#1}}%
\savefinalpage
}
\makeatother
\begin{document}
\listoffigures
\clearpage
\begin{figure}
\captionsetup{list=no}
\centering
\subfloat[][]{\includegraphics[height=1cm]{fig1}}\\
\subfloat[][]{\includegraphics[height=1cm]{fig2}}
\caption{A result that requires two pages. \emph{(cont.)}}
\MyCaption{A result that requires two pages}
\end{figure}
\clearpage\mbox{}\clearpage
\begin{figure}
\caption{test}
\end{figure}
\begin{figure}[!b]
\captionsetup{list=no}
\ContinuedFloat
\centering
\subfloat[][]{\includegraphics[height=1cm]{fig3}}\\
\subfloat[][]{\includegraphics[height=1cm]{fig4}}
\MyCaptionE{A result that requires two pages.}
\end{figure}
\end{document}
评论:
最后两个代码值得解释一下,但不幸的是,目前我无法提供。我会尽快提供。
答案2
我尝试做类似的事情,并找到了你的答案。我不喜欢每次想要使用它时都必须做出多个新定义。所以我尝试以不同的方式解决问题。我是新手,所以也许有充分的理由不按照我建议的方式去做……
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage[linktocpage,colorlinks=true]{hyperref}
\DeclareCaptionLabelFormat{continued}{#1~#2~(cont.)}
\captionsetup[ContinuedFloat]{labelformat=continued}
\def\MyCaption#1#2#3{\addtocontents{lof}{\protect\contentsline{figure}{\protect\numberline{\thefigure}{\ignorespaces #1\relax}}{{\pageref{#2}}--{\pageref{#3}}}{}}}
\begin{document}
\listoffigures
\clearpage
\begin{figure}
\captionsetup{list=no}
\centering
\includegraphics[height=1cm]{fig1}
\caption{A result that requires two pages.}
\label{fig:part1}
\end{figure}
\clearpage
\begin{figure}
\captionsetup{list=no}
\ContinuedFloat
\centering
\includegraphics[height=1cm]{fig2}
\caption{A result that requires two pages.}
\label{fig:part2}
\MyCaption{A result that requires two pages}{fig:part1}{fig:part2}
\end{figure}
\clearpage
\begin{figure}
\captionsetup{list=no}
\centering
\includegraphics[height=1cm]{fig3}
\caption{Another result that requires two pages.}
\label{fig:part3}
\end{figure}
\clearpage
\begin{figure}
\captionsetup{list=no}
\ContinuedFloat
\centering
\includegraphics[height=1cm]{fig4}
\caption{Another result that requires two pages.}
\label{fig:part4}
\MyCaption{Another result that requires two pages}{fig:part3}{fig:part4}
\end{figure}
\end{document}
答案3
如果您不需要页面范围而只是想避免多个条目,只需添加
\captionsetup[ContinuedFloat]{list=false}
回到序言。
当然,这并没有回答实际的问题,但那行代码正是我试图在谷歌上搜索的内容,也是我提出这个问题的原因。我花了一段时间才找到解决方案,因为其他答案都很复杂,所以我想把这个留在这里,为谷歌用户节省几秒钟的时间。
答案4
我建议添加带有超链接的解决方案,以便在图表和章节及页面列表中添加超链接。
\documentclass{scrbook}
\usepackage{hyperref}
\hypersetup{colorlinks,%
citecolor=blue,%
filecolor=blue,%
linkcolor=orange,%
urlcolor=blue}
\usepackage{todonotes}
\usepackage{tocloft}
\usepackage{lipsum}
\usepackage{showframe}
\makeatletter
\def\myaddcontentsline#1#2#3{%
\addtocontents{#1}{\protect\contentsline{#2}{#3}{see \thesection\ at p. \thepage}{\@currentHref}}}
\renewcommand{\@todonotes@addElementToListOfTodos}{%
\if@todonotes@colorinlistoftodos%
\myaddcontentsline{tdo}{todo}{{%
\colorbox{\@todonotes@currentbackgroundcolor}%
{\textcolor{\@todonotes@currentbackgroundcolor}{o}}%
\ \@todonotes@caption}}%
\else%
\myaddcontentsline{tdo}{todo}{{\@todonotes@caption}}%
\fi}%
\newcommand*\mylistoftodos{%
\begingroup
\setbox\@tempboxa\hbox{see 9.9 at p. 99}%
\renewcommand*\@tocrmarg{\the\wd\@tempboxa}%
\renewcommand*\@pnumwidth{\the\wd\@tempboxa}%
\listoftodos%
\endgroup
}
\makeatother
\begin{document}
\chapter{My first chapter}
\section{A first section}
\lipsum
\todo{This is a note}
\section{Another section}
\lipsum
\todo{This is another note}
\mylistoftodos
\end{document}
hyperref 命令 addcontentsline 的解释是重新定义的,它带有四个参数。第四个参数必须为 @currentHref 给出的超链接提供目标。