12

I am using the \ContinuedFloat command of the subfig package to print a series of figures in more than one page. I would like to have one caption in the List of Figures and "compress" the pages so that only the first and the last are shown.

EDIT: Since I am using also the cleveref package, I would like to have a link for both the pages. So it should be 2 --> links to page 2, 3 --> links to page 3, and the hyphen that is a "neutral" symbol.

For example, what I get now is:

List of Figures

  1. A result that requires two pages. (cont.) 2
  2. A result that requires two pages 3

while I would like to have:

List of Figures

  1. A result that requires two pages 2-3

Here is the 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}
David Carlisle
  • 757,742
mp87
  • 825
  • I think you meant hyperref and not cleveref? After all, hyperlinks are created by the former. – Gonzalo Medina Apr 07 '12 at 03:46
  • 1
    I have never seen a range of page numbers in the List of whatever; only the first page. For instance, you don't see "First Chapter ... 1–42" in the ToC. – Mike T Jan 07 '16 at 00:13

5 Answers5

11

Simply use an empty optional argument for \caption in the continuation (and the optional argument in the first \caption if you want to get rid of "(cont)" in the list of figures):

\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}

enter image description here

I changed some of the settings so that the example will fit in just one page.

I originally didn't see the requirement concerning the page numbering in the LoF; here's now a solution:

\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}

enter image description here

Now another version with the new requirements; in particular, it requires loading 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}

A new version that improves the anchoring of the hyperlink for the continuation:

\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}

Remark:

These last two codes deserve some explanation but unfortunately right now I won't be able to provide it. As soon as I can I will do so.

Moriambar
  • 11,466
Gonzalo Medina
  • 505,128
  • Hi @Gonzalo, thanks for your reply. Unfortunately, your solution doesn't fulfill completely my request. If the first subfigure starts, say, at page 5 and the last one is at page 8, I want the List of Figures to explicitly report "5-8". With the code you proposed, it would write only the page of the first subfigure, that is "5". – mp87 Apr 06 '12 at 18:16
  • @mp87: I am working on it. I'll let you know when I post an update. – Gonzalo Medina Apr 06 '12 at 18:20
  • @mp87:please see my updated answer. – Gonzalo Medina Apr 06 '12 at 19:34
  • Your solution is nice, but I need to use it in a document that is more complex than the example I provided. I'll update my first post to add more info. The problem I that your code writes this row inside the .lof file: \contentsline {figure}{\numberline {1}A result that requires two pages.}{2--4} while usually it should be: \contentsline {figure}{\numberline {1}{A result that requires two pages.}{2--4}{figure.caption.1} The second problem is that I would like to have a link to the two pages, that is 2 --> figure.caption.1, 4 --> figure.caption.2. – mp87 Apr 06 '12 at 23:18
  • @mp87: see my updated answer. – Gonzalo Medina Apr 07 '12 at 03:45
  • Thanks for the excellent work! There's only a little thing left to fix: the line inside the .lof file is \contentsline {figure}{\numberline {1}A result that requires two pages.}{\hyperlink {xyzs}{2}--\hyperlink {xyzf}{4}}{} while it should be \contentsline {figure}{\numberline {1}{A result that requires two pages.}{\hyperlink {xyzs}{figure.caption.1}--\hyperlink {xyzf}{figure.caption.2}}{} (notice also the additional left brace in the latter). At the moment, the code just redirect to the page of the figure, but not at the figure's actual position. – mp87 Apr 07 '12 at 10:19
  • @mp87: no; with your suggestion, the texts "figure.caption.1" and "figure.caption.2" will appear in the list of figures right after the each page number; perhaps the last argument could be used, but I don't see clearly how since there would be two possible values to be used. For the moment, I don't see how to improve the anchoring. – Gonzalo Medina Apr 07 '12 at 16:15
  • @mp87: I've added a new version that (I think) improves the anchoring at least for the continuation, but I'd rather use the previous one ;-) – Gonzalo Medina Apr 07 '12 at 16:31
  • could you please help me in fixing the problem with the counter? See my post below. Thank you very much! – mp87 Apr 14 '12 at 21:25
1

I was trying to do something similar, and found your answer. I don't really like to have to make multiple new definitions every time I want to use this. So I tried to solve it differently. I'm new to this so maybe there's a good reason not to do it the way I suggested...

\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}
Ralf
  • 11
1

If you don't need the range of pages and just want to avoid the multiple entries, just add

\captionsetup[ContinuedFloat]{list=false}

to the preamble.

Of course this doesn't answer the actual question, but that specific line is what I was trying to google and what brought me to this question. It took me a while to figure out the solution since the other answers are quite convoluted, so I thought I'll leave this here to save fellow googlers a few seconds of their lives.

MaxD
  • 1,137
0

@Gonzalo: Sorry for the late answer. I hacked a bit your code, and I finally found a satisfying solution. I report it here, in the hope that can be helpful to someone else.

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subfig}
\usepackage[linktocpage,colorlinks=true]{hyperref}

\makeatletter
\def\myaddcontentsline#1#2#3#4#5{%
\addtocontents{#1}{\protect\contentsline{#2}{#3}%
    {\protect\hyperref[#4]{\thepage}--\protect\hyperref[#5]{\finalpage}}{}}%
}

\gdef\finalatpage#1{\gdef\finalpage{#1}}
\finalatpage{0}

\def\MyCaption#1#2#3{%
  \myaddcontentsline{lof}{figure}{\protect\numberline{\thefigure}{\ignorespaces #1\relax }}{#2}{#3}%
}

\def\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.)}}
  \label{fig:part1}
  \MyCaption{A result that requires two pages}{fig:part1}{fig:part2}
\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.}
  \label{fig:part2}
  \savefinalpage
\end{figure}

\end{document}

Basically I substituted the hypertarget command with hyperref and introduced the target objects in the definition of myaddcontentsline. I know that this solution is pretty rough, so please let me know if it is possible to improve it.

Edit:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subfig}
\usepackage[linktocpage,colorlinks=true]{hyperref}

\makeatletter
\gdef\finalatpage#1{\gdef\finalpage{#1}}
\finalatpage{0}
\gdef\finalatpagei#1{\gdef\finalpagei{#1}}
\finalatpagei{0}

\def\MyCaption#1#2#3#4{%
\addtocontents{lof}{\protect\contentsline{figure}{#1}%
    {\protect\hyperref[#2]{\thepage}--\protect\hyperref[#3]{#4}}{}}%
}

\def\savefinalpage{\makeatletter
  \write\@auxout{\protect\finalatpage{\arabic{page}}}
  \makeatother
}
\def\savefinalpagei{\makeatletter
  \write\@auxout{\protect\finalatpagei{\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.)}}
  \label{fig:part1}
  \MyCaption{A result that requires two pages}{fig:part1}{fig:part2}{\finalpage}
\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.}
  \label{fig:part2}
  \savefinalpage
\end{figure}

\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.)}}
  \label{fig:part3}
  \MyCaption{Another result that requires two pages}{fig:part3}{fig:part4}{\finalpagei}
\end{figure}

\clearpage\mbox{}\clearpage

\begin{figure}
  \captionsetup{list=no}
  \ContinuedFloat
  \centering
  \subfloat[][]{\includegraphics[height=1cm]{fig3}}\\
  \subfloat[][]{\includegraphics[height=1cm]{fig4}}
  \caption{Another result that requires two pages.}
  \label{fig:part4}
  \savefinalpagei
\end{figure}

\end{document}

Edit:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subfig}
\usepackage[linktocpage,colorlinks=true]{hyperref}

\makeatletter
\gdef\finalatpage#1{\gdef\finalpage{#1}}
\finalatpage{0}
\gdef\finalatpagei#1{\gdef\finalpagei{#1}}
\finalatpagei{0}

\def\MyCaption#1#2#3#4{%
\addtocontents{lof}{\protect\contentsline{figure}{\protect\numberline{\thefigure}{\ignorespaces #1\relax}}%
    {\protect\hyperref[#2]{\thepage}--\protect\hyperref[#3]{#4}}{}}%
}

\def\savefinalpage{\makeatletter
  \write\@auxout{\protect\finalatpage{\arabic{page}}}
  \makeatother
}
\def\savefinalpagei{\makeatletter
  \write\@auxout{\protect\finalatpagei{\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.)}}
  \label{fig:part1}
  \MyCaption{A result that requires two pages}{fig:part1}{fig:part2}{\finalpage}
\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.}
  \label{fig:part2}
  \savefinalpage
\end{figure}

\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.)}}
  \label{fig:part3}
  \MyCaption{Another result that requires two pages}{fig:part3}{fig:part4}{\finalpagei}
\end{figure}

\clearpage\mbox{}\clearpage

\begin{figure}
  \captionsetup{list=no}
  \ContinuedFloat
  \centering
  \subfloat[][]{\includegraphics[height=1cm]{fig3}}\\
  \subfloat[][]{\includegraphics[height=1cm]{fig4}}
  \caption{Another result that requires two pages.}
  \label{fig:part4}
  \savefinalpagei
\end{figure}

\end{document}
David Carlisle
  • 757,742
mp87
  • 825
  • I spoke too soon, there is a problem with the counter defined by savefinalpage. Since I am using the code twice, in the second case \finalpage is overwritten, and I find it twice in the List of Figures. So what I find is something like:
    1. Figure 1. A results that requires two pages 2-7
    2. Figure 2. A results that requires other two pages 6-7

    while the Figure 1 is covering pages 2 and 3.

    – mp87 Apr 12 '12 at 17:07
  • In the edit to your answer I've provided perhaps not the most elegant solution (it duplicates definitions), but it will produce the desired output. When I have some time I'll try to improve it. – Gonzalo Medina Apr 16 '12 at 00:34
  • @GonzaloMedina: Thank you! It doesn't matter if it's not elegant, it works like a charm! P.S. I improved slightly the definition of MyCaption. – mp87 Apr 16 '12 at 15:04
0

I suggest to add solution with hyperref to have hyperlink in list of figure and section & page added.

\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}

explanation with hyperref command addcontentsline is redefined and is taking four parameter. The fourth parameter must give destination for hyperlink given by @currentHref.

I Thank a lot Ulrike Fischer who help me to solve the main problem with the fourth parameter. enter image description here

Manmax
  • 11