有些书的几页只包含一张图片,没有页脚、页眉或类似的东西。我希望有类似的东西,尽管我想保持统一的边距、图像的纵横比和标题。我还希望页面根据pdflscape
图像的尺寸旋转。
它在或多或少的 MWE 中的使用方式如下:
documentclass[a5paper]{article}
\usepackage{picturepage}
\usepackage[hidelinks]{hyperref}
\begin{document}
\picturepage{some_portrait_picture}{This is a portrait picture. \href{http://www.flickr.com/photos/thomasleuthard/}{Thomas Leuthard} took it in France and released it under the \href{http://creativecommons.org/licenses/by/2.0/}{Creative Commons attribution licence} on Flickr.}{fig:portrait}
\picturepage{some_landscape_picture}{This is a landscape picture. It was released under the \href{http://creativecommons.org/licenses/by/2.0/}{Creative Commons attribution licence} by someone calling himself ``\href{http://www.flickr.com/photos/80901381@N04/}{A Guy Taking Pictures}'' on Flickr.}{fig:landscape}
\end{document}
这可能是这样的:
我将在一个答案中发布我对这个问题的看法。欢迎大家修改我的代码或发布自己的答案。想出比我做的更漂亮的答案应该不难。
这些是我使用的图片。如果你不想看那些无聊的mwe
东西,这可能会为那些想要获取一些 Create Commons 图片来玩的人节省一些时间:http://www.flickr.com/photos/80901381@N04/7758832526/和http://www.flickr.com/photos/thomasleuthard/6106078656/
答案1
所以我的看法是,TOC caption 可选参数现在的位置可能不太理想,而应该放在 cation 参数之前或之后。此外 caption 和 label 也可以是可选参数。我想这样代码就会干净得多。案例的区别使这段代码变得比必要的更复杂,但不知何故我无法对横向和纵向使用相同的方法。
% Provides full page picture command
% \picturepage[TOC caption]{picture}{caption}{label}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{picturepage}[2012/04/16 v0.1 Picture Page]
\newlength{\maxpicturewidth}
\newlength{\maxpictureheight}
\newlength{\maxfigureheight}
\newlength{\pictureheight}
\newlength{\picturewidth}
\newlength{\totalfigureheight}
\newlength{\captionheight}
\newlength{\originalpicturewidth}
\newlength{\originalpictureheight}
\newlength{\picturehoffset}
\newlength{\picturevoffset}
\newlength{\vmargin}
\newlength{\subpictureskip}
\setlength{\subpictureskip}{0pt}
\newsavebox{\captionbox}
\newcounter{recalccounter}
\RequirePackage{pdflscape}
%\RequirePackage{lscape}
\RequirePackage{graphicx}
\RequirePackage{ifthen}
\RequirePackage{calc}
\RequirePackage[absolute]{textpos}
\RequirePackage{geometry}[2010/09/12]
\RequirePackage{afterpage}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% \picturepage[ToC caption]{file}{caption}{label} %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\picturepage}[4][\empty]{%
%\afterpage{
\clearpage
\thispagestyle{empty}%
\settowidth{\originalpicturewidth}{\includegraphics{#2}}%
\settoheight{\originalpictureheight}{\includegraphics{#2}}%
% check if we have a landscape picture
\ifthenelse{\lengthtest{\originalpicturewidth > \originalpictureheight}}{%
%%% landscape %%%
\newgeometry{textheight=\paperheight,textwidth=\paperwidth}%
\begin{landscape}%
\begin{figure}%
% set max picture dimensions
\setlength{\maxpictureheight}{.9\paperwidth}% TODO: make width/height depend
\setlength{\maxpicturewidth}{.9\paperheight}% on orientation one day
\setlength{\maxfigureheight}{\maxpictureheight}%
% calculate picture and caption dimensions including caption until it fits
\setlength{\captionheight}{\baselineskip}%
\setcounter{recalccounter}{0}%
\setlength{\totalfigureheight}{1.01\maxfigureheight+1pt}% force 1st iteration
\whiledo{\lengthtest{\totalfigureheight>1.01\maxfigureheight} % give some leeway
\AND \value{recalccounter}<10}{% if we don't converge in 10 iterations, give up
\ifthenelse{\value{recalccounter}>0}{%
\typeout{picture too high, recalculating (iteration \arabic{recalccounter})}%
}{}%
% calc initial picture dimensions
\setlength{\maxpictureheight}{\maxfigureheight-\captionheight-\subpictureskip}%
\settoheight{\pictureheight}{\includegraphics[width=\maxpicturewidth,%
height=\maxpictureheight, keepaspectratio=true, draft]{#2}}%
\settowidth{\picturewidth}{\includegraphics[width=\maxpicturewidth,%
height=\maxpictureheight, keepaspectratio=true, draft]{#2}}%
% measure caption height with initial picture dimensions
\savebox{\captionbox}{\parbox{\picturewidth}{%
\ifthenelse%
{\equal{#1}{\empty}}%
{\caption{#3}}%
{\caption[#1]{#3}}%
}%
\addtocounter{figure}{-1}%
}%
\settoheight{\captionheight}{\usebox{\captionbox}}%
% measured magic factor, total weirdness, should *so* be 1.0!
\setlength{\captionheight}{1.9\captionheight}%
% calc intial figure height including caption
\setlength{\totalfigureheight}{\pictureheight+\captionheight+\subpictureskip}%
\stepcounter{recalccounter}%
}%
\centering%
\includegraphics[width=\maxpicturewidth,%
height=\maxpictureheight, keepaspectratio=true]{#2}\vspace{\subpictureskip}
\usebox{\captionbox}\label{#4}%
\end{figure}%
\end{landscape}%
\restoregeometry
}{%%% portrait %%%
\setlength{\vmargin}{\topmargin}
\addtolength{\vmargin}{1in}
\addtolength{\vmargin}{\headheight}
\addtolength{\vmargin}{\headsep}
\addtolength{\vmargin}{\topskip}
\begin{figure}%
% set max picture dimensions
\setlength{\maxpictureheight}{.9\paperheight}%
\setlength{\maxpicturewidth}{.9\paperwidth}%
\setlength{\maxfigureheight}{\maxpictureheight}%
% calculate picture and caption dimensions including caption until it fits
\setlength{\captionheight}{\baselineskip}%
\setcounter{recalccounter}{0}%
\setlength{\totalfigureheight}{1.01\maxfigureheight+1pt}% force 1st iteration
\whiledo{\lengthtest{\totalfigureheight>1.01\maxfigureheight} % give some leeway
\AND \value{recalccounter}<10}{% if we don't converge in 10 iterations, give up
\ifthenelse{\value{recalccounter}>0}{%
\typeout{picture too high, recalculating (iteration \arabic{recalccounter})}%
}{}%
% calc initial picture dimensions
\setlength{\maxpictureheight}{\maxfigureheight-\captionheight}%
\settoheight{\pictureheight}{\includegraphics[width=\maxpicturewidth,%
height=\maxpictureheight, keepaspectratio=true, draft]{#2}}%
\settowidth{\picturewidth}{\includegraphics[width=\maxpicturewidth,%
height=\maxpictureheight, keepaspectratio=true, draft]{#2}}%
% measure caption height with initial picture dimensions
\savebox{\captionbox}{\parbox{\picturewidth}{%
\begingroup%
\ifthenelse%
{\equal{#1}{\empty}}%
{\caption{#3}}%
{\caption[#1]{#3}}%
\endgroup%
}%
\addtocounter{figure}{-1}%
}%
\settoheight{\captionheight}{\usebox{\captionbox}}%
% measured magic factor, total weirdness, should *so* be 1.0!
\setlength{\captionheight}{1.9\captionheight}%
% calc intial figure height including caption
\setlength{\totalfigureheight}{\pictureheight+\captionheight}%
\stepcounter{recalccounter}%
}%
\setlength{\picturevoffset}{\paperheight-\totalfigureheight}%
\setlength{\picturevoffset}{.5\picturevoffset}%
\setlength{\picturehoffset}{\paperwidth-\picturewidth}%
\setlength{\picturehoffset}{.5\picturehoffset}%
\begin{textblock*}{\picturewidth}(\picturehoffset,\picturevoffset)
\centering
\includegraphics[width=\maxpicturewidth,%
height=\maxpictureheight, keepaspectratio=true]{#2}\vspace{\subpictureskip}
\usebox{\captionbox}\label{#4}%
\end{textblock*}
\null\clearpage
\end{figure}%
}%
\addtocounter{figure}{1}%
\clearpage%
}%}