我想将图形放在偶数页上,然后将标题放在下一页上。
原因是图形 + 标题太大,无法放在一页中,但我希望读者能够同时看到图像和标题。
以下是使用 xelatex 编译的 MWE:
\documentclass[12pt,english]{extbook}
\usepackage{fontspec}
\usepackage{xunicode}
\usepackage[a4paper]{geometry}
\usepackage[english]{babel}
\usepackage{caption}
\usepackage{afterpage}
\usepackage{ifoddpage}
\usepackage{blindtext}
% Create big picture
\renewcommand{\includegraphics}[2][]{%
\setlength{\fboxsep}{-\fboxrule}%
\framebox{\rule{0pt}{15cm}\rule{10cm}{0pt}}%
}
% Add figure on even page and caption on odd page, plus a ruler to separate caption from text
\newcommand{\doublesidefigurewithruler}[5][1]{%
\afterpage{
\newpage
\checkoddpage
\ifoddpage
\doublesidefigurewithruler[#1]{#2}{#3}{#4}{#5}
\else
\doublesidefigurecontent{#1}{#2}{#3}{#4}{#5}{1}
\fi
}
}%
% Add the figure and the caption
\newcommand{\doublesidefigurecontent}[6]{%
\begin{center}
\vspace*{\fill}
\includegraphics[width=#1\textwidth]{#2}
\captionof{figure}[]{#4}
\label{#3}
\vspace*{\fill}
\end{center}
\newpage
\addtocounter{figure}{-1}
\captionof{figure}[#4]{#4 #5}
\ifnum \numexpr#6=1
\noindent\rule{\textwidth}{0.2pt}
\fi
}%
\begin{document}
\Blindtext
\doublesidefigurewithruler[1]{%
bigfigure}{%
mylabel}{%
Mytitle}{%
\blindtext
\blindtext
}
\Blindtext
\Blindtext
\Blindtext
\end{document}
它确实有效,但可能有更好的方法,对吧?此外,如果我将其与常规图形环境混合使用,图形编号有时会出错,我必须\clearpage
在两者之间添加\doublesidefigurewithruler...
。
此外,如果可能的话,我更愿意将标题放在下一页的底部,并且我更愿意拥有一个环境:
\begin{doublesidefigure}
\centering
\includegraphics...
\caption[for the toc]{My content}
\label{mylabel}
\end{doublesidefigure}
我的方法有效,但不太可靠。我该如何正确操作?
答案1
我认为您打算添加一个很长的标题,因为现在看起来有点奇怪。您确定不想将标题放在页边距中吗?
顺便说一句,由于奇数页测试是在新页面的开始处,因此页面计数器是准确的。
\documentclass[12pt,english]{extbook}
%\usepackage{fontspec}% don't need them myself
%\usepackage{xunicode}
\usepackage[a4paper]{geometry}
\usepackage[english]{babel}
\usepackage{caption}
\usepackage{afterpage}
\usepackage{environ}
\usepackage{mwe}
\usepackage{showframe}
\newsavebox{\doublepagecaption}
\newsavebox{\doublepageimage}
\NewEnviron{doublepagefigure}[2][]% #1=short caption (optional), #2=caption
{\global\setbox\doublepagecaption=\hbox{%
\parbox{\textwidth}{\captionof{figure}[#1]{#2}}}%
\global\setbox\doublepageimage=\hbox{\parbox{\textwidth}{\BODY}}%
\afterpage{\clearpage
\ifodd\value{page}%
\afterpage{%
\vspace*{\fill}\vspace{-\baselineskip}%
\noindent\usebox{\doublepageimage}\vfill\pagebreak
\begin{figure}[b]\usebox{\doublepagecaption}\end{figure}}%
\else
\vspace*{\fill}\vspace{-\baselineskip}%
\noindent\usebox{\doublepageimage}\vfill\pagebreak
\begin{figure}[b]\usebox{\doublepagecaption}\end{figure}%
\fi}}
\renewcommand{\bottomfraction}{0.5}% fraction of page allowed for bottom floats
\begin{document}
\listoffigures
\bigskip
Reference to Figure \ref{fig:test}.
\bigskip
\lipsum[1]
\begin{doublepagefigure}[short caption]{long caption\label{fig:test}}
\centering\fbox{\includegraphics[width=.95\textwidth,height=.95\textheight]{example-image}}
\end{doublepagefigure}
\lipsum[2-16]
\end{document}
\afterpage
等待分页符执行。如果段落被拆分,它将在后半部分之前插入文本。调用\afterpage
inside\afterpage
等待两页,依此类推。
\clearpage
强制立即打印所有未完成的浮点数,即使它增加了一页。(您可能不需要它,但通常您希望以正确的顺序打印浮点数。)
我使用框寄存器来实现图形和标题,就像普通浮点数一样。系统足够智能,可以延迟写入目录,直到框显示出来。它还会立即增加图形计数器。
所有局部定义在环境结束时都会丢失,并且\savebox
是局部定义。因此\global\setbox\name=\hbox{...}
形式如下。
这是风格更新的版本。它不需要 environ 或 caption 包。
\documentclass[12pt,english]{extbook}
%\usepackage{fontspec}% don't need them myself
%\usepackage{xunicode}
\usepackage[a4paper]{geometry}
\usepackage[english]{babel}
\usepackage{afterpage}
\usepackage{graphicx,lipsum}
\usepackage{showframe}
\newsavebox{\doublepagecaption}
\newsavebox{\doublepageimage}
\makeatletter
\newenvironment{doublepagefigure}[2][]% #1=short caption (optional), #2=caption
{\def\@captype{figure}%
\global\setbox\doublepagecaption=\vbox{\caption[#1]{#2}}%
\begin{lrbox}{\doublepageimage}}% body goes here
{\end{lrbox}%
\global\setbox\doublepageimage=\box\doublepageimage
\afterpage{\clearpage
\ifodd\value{page}%
\afterpage{%
\vspace*{\fill}\vspace{-\baselineskip}%
\noindent\usebox{\doublepageimage}\vfill\pagebreak
\begin{figure}[b]\usebox{\doublepagecaption}\end{figure}}%
\else
\vspace*{\fill}\vspace{-\baselineskip}%
\noindent\usebox{\doublepageimage}\vfill\pagebreak
\begin{figure}[b]\usebox{\doublepagecaption}\end{figure}%
\fi}}
\makeatother
\renewcommand{\bottomfraction}{0.5}% fraction of page allowed for bottom floats
\begin{document}
\listoffigures
\bigskip
Reference to Figure \ref{fig:test}.
\bigskip
\lipsum[1]
\begin{doublepagefigure}[short caption]{long caption\label{fig:test}}
\centering\fbox{\includegraphics[width=.95\textwidth,height=.95\textheight]{example-image}}
\end{doublepagefigure}
\lipsum[2-16]
\end{document}