我想制作多个子图,如果它们之间有分页符,那么我希望主标题出现在每一页上(如果我使用 \ref{} 引用,它应该只转到第一个)。像这样:
\documentclass{scrartcl}%
\usepackage{lipsum}
\usepackage{float}%
\usepackage{scrhack}%
\usepackage{graphicx}%
\usepackage[hypcap=true]{caption}%
\usepackage[list=true,hypcap=true]{subcaption}%
\usepackage{hyperref}%
\begin{document}
\lipsum[1-3]% CHANGE 3 to 4 for pagebreak between figure a and b
\begin{figure}[H]%
\hfill%
\subcaptionbox{Dummy 1.\label{subfig:Dummy1}}{\includegraphics[width=0.5\textwidth]{example-image-a}}%
\hspace*{\fill}%
% I want this caption ONLY if pictures A and B are on the same, else only the caption below should be printed. (Ofc the label should than also be below)
\caption{Main caption.}%
\label{fig:Dummy}%
\end{figure}%
\begin{figure}[H]\ContinuedFloat%
\hfill%
\subcaptionbox{Dummy 2.\label{subfig:Dummy2}}{%
\includegraphics[width=0.5\textwidth]{example-image-b}}%
\hspace*{\fill}%
\caption{Main caption.}%
\end{figure}%
% Test references
\lipsum[1]
Figure (a): \ref{subfig:Dummy1}\\
Figure (b): \ref{subfig:Dummy2}\\
Figure (1): \ref{fig:Dummy}\\
\lipsum[1-4]
\end{document}
导致:
当然这不是一个可行的例子^^,因为它导致
如果两个图都在同一页上。如果子图不在不同的页面上,我希望只有一个主标题(底部)。有什么建议吗?:D
答案1
图表会立即格式化,因此获取页码的唯一方法是通过辅助文件 ( \getpagerefnumber
)。它由 hyperref 提供,但请参阅 refcount 了解文档。
注意:需要两次运行才能反映页码的变化。
移动锚点最简单的方法是使用\hyperlink{...}{\ref*{...}}
而不是\ref
。另一种方法是在和\@currentHref
之间切换。\caption
\label
\documentclass{scrartcl}%
\usepackage{lipsum}
\usepackage{float}%
\usepackage{scrhack}%
\usepackage{graphicx}%
\usepackage[hypcap=true]{caption}%
\usepackage[list=true,hypcap=true]{subcaption}%
\usepackage{hyperref}%
\begin{document}
\lipsum[1-4]% CHANGE 3 to 4 for pagebreak between figure a and b
\begin{figure}[H]%
\hypertarget{fig:Dummy}%
\hfill%
\subcaptionbox{Dummy 1.\label{subfig:Dummy1}}{\includegraphics[width=0.5\textwidth]{example-image-a}}%
\hspace*{\fill}%
\ifnum\getpagerefnumber{subfig:Dummy2}>\getpagerefnumber{subfig:Dummy1}\relax
\caption{Main caption.}%
\fi
\end{figure}%
\begin{figure}[H]\ContinuedFloat%
\hfill%
\subcaptionbox{Dummy 2.\label{subfig:Dummy2}}{%
\includegraphics[width=0.5\textwidth]{example-image-b}}%
\hspace*{\fill}%
\caption{Main caption.}%
\label{fig:Dummy}%
\end{figure}%
% Test references
\lipsum[1]
Figure (a): \ref{subfig:Dummy1}\\
Figure (b): \ref{subfig:Dummy2}\\
Figure (1): \hyperlink{fig:Dummy}{\ref*{fig:Dummy}}\\
\lipsum[1-4]
\end{document}
答案2
我找到了另一个解决方案 (@John),它现在可以与分页符一起使用,并且始终引用顶部图片,以\ref{fig:Dummy}
独立判断图片是否在同一侧。:D我不知道下面和顶部的空间现在是否与图形环境完全相同(如果有人知道,我会很高兴),但至少它可以工作并且看起来完全一样。顺便说一句,它需要\usepackage[breakable,skins]{tcolorbox}
我总是加载的包。
\begin{tcolorbox}[%
breakable,%
arc=0mm, boxrule=0pt, frame hidden,%
left=0pt, right = 0pt, top=0pt, bottom=1mm, boxsep=0pt,%
enhanced standard jigsaw,%
after skip=1\baselineskip,%
before skip=1\baselineskip,%
opacityback=0,%
]%
{\captionsetup{type=figure}%
\hfill%
\subcaptionbox{Dummy 1.\label{subfig:Dummy1}}{\includegraphics[width=0.5\textwidth]{example-image-a}}%
\hspace*{\fill}%
\ifnum\getpagerefnumber{subfig:Dummy1}<\getpagerefnumber{subfig:Dummy2}\relax
\caption{Main caption.}%
\ContinuedFloat%
\fi%
\par%
\hfill%
\subcaptionbox{Dummy 2.\label{subfig:Dummy2}}{\includegraphics[width=0.5\textwidth]{example-image-b}}%
\hspace*{\fill}%
\caption{Main caption.}%
\label{fig:Dummy}%
}%
\end{tcolorbox}%