图片列表后出现“\addcontentsline{toc}{section}”的错误页面

图片列表后出现“\addcontentsline{toc}{section}”的错误页面

请参阅本消息末尾提供的代码,其中的图表可供下载这里(它只是一个矩形的 pdf)。问题是,\addcontentsline{toc}{section}在所有图片之后,链接到了错误的页面。如何让它链接到准确的页面?(不改变当前图片的对齐方式,每页 2 个图片垂直居中,没有文本)。结果是这里问题如下所示: 在此处输入图片描述

% DOCUMENT TYPE
\documentclass[a4paper]{book}
\usepackage[english]{babel}
\usepackage[margin=10pt,font=footnotesize,labelfont=bf]{caption}
\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{pgffor}
\usepackage{xifthen}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{hyperref}

% HEADER AND FOOTER
\fancyhf{}
\renewcommand{\headrulewidth}{1pt}
\renewcommand{\footrulewidth}{1pt}
\fancyhead[LO]{\rightmark}   
\fancyhead[RE]{\leftmark}
\fancyfoot[CE,CO]{\thepage}

% INVISIBLE SECTION
\newcommand\invisiblesection[1]{\refstepcounter{section}\addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}\sectionmark{#1}}

% DOCUMENT INFORMATION
\title{Title}
\author{Author}
\date{\today}

% DOCUMENT
\begin{document}
\maketitle
\tableofcontents
\mainmatter
\chapter{First chapter}
\section{First section}
\lipsum
\lipsum
\lipsum
\lipsum
\section{Second section}
\lipsum
\lipsum
\lipsum
\lipsum
\chapter{Second chapter}
\foreach\n in {1,3,...,17}{% 
\ifthenelse{\cnttest{\n}{=}{1}}{\invisiblesection{First section}}{}
\ifthenelse{\cnttest{\n}{=}{5}}{\invisiblesection{Second section}}{}
\ifthenelse{\cnttest{\n}{=}{9}}{\invisiblesection{Third section}}{}
\ifthenelse{\cnttest{\n}{=}{13}}{\invisiblesection{Fourth section}}{}
\begingroup\fboxsep=0pt
\begin{figure}[!p]
\makebox[\textwidth][c]{\fbox{\includegraphics[page=1, width=\textwidth]{pdfpage.pdf}}}
\end{figure}
\begin{figure}[!p]
\makebox[\textwidth][c]{\fbox{\includegraphics[page=1, width=\textwidth]{pdfpage.pdf}}}
\end{figure}
\endgroup
\clearpage
}
\chapter{Third chapter}
\section{First section}
\lipsum
\lipsum
\lipsum
\lipsum
\section{Second section}
\lipsum
\lipsum
\lipsum
\lipsum
\end{document}

答案1

因为无论如何都不鼓励浮动......

vincentInvisibleSection

% DOCUMENT TYPE
\documentclass[a4paper]{book}
\usepackage[english]{babel}
\usepackage[margin=10pt,font=footnotesize,labelfont=bf]{caption}
\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{pgffor}
\usepackage{afterpage}
\usepackage{xifthen}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage[pdfpagelabels]{hyperref}

% HEADER AND FOOTER
\fancyhf{}
\renewcommand{\headrulewidth}{1pt}
\renewcommand{\footrulewidth}{1pt}
\fancyhead[LO]{\rightmark}   
\fancyhead[RE]{\leftmark}
\fancyfoot[CE,CO]{\thepage}

% INVISIBLE SECTION
\newcommand\invisiblesection[1]{\refstepcounter{section}\addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}\sectionmark{#1}}

% DOCUMENT INFORMATION
\title{Title}
\author{Author}
\date{\today}

% DOCUMENT
\begin{document}
\maketitle
\tableofcontents
\mainmatter
\chapter{First chapter}
\section{First section}
\lipsum
\lipsum
\lipsum
\lipsum
\section{Second section}
\lipsum
\lipsum
\lipsum
\lipsum
\chapter{Second chapter}
\foreach\n in {1,3,...,17}{% 
    \ifthenelse{\cnttest{\n}{=}{1}}{\invisiblesection{First section}}{}
    \ifthenelse{\cnttest{\n}{=}{5}}{\invisiblesection{Second section}}{}
    \ifthenelse{\cnttest{\n}{=}{9}}{\invisiblesection{Third section}}{}
    \ifthenelse{\cnttest{\n}{=}{13}}{\invisiblesection{Fourth section}}{}
    \begingroup\fboxsep=0pt
    \setlength{\parindent}{0pt}
        \fbox{\includegraphics[page=1, width=\textwidth]{example-image.pdf}}
        \fbox{\includegraphics[page=1, width=\textwidth]{example-image.pdf}}
    \endgroup
    \clearpage
}
\chapter{Third chapter}
\section{First section}
\lipsum
\lipsum
\lipsum
\lipsum
\section{Second section}
\lipsum
\lipsum
\lipsum
\lipsum
\end{document}

相关内容