
這是困難的一個。我有很多情況,我開始新的章節,新章節的第一頁是一個pdf頁面,它是使用加載的\includegraphics
(我有很多文檔,我掃描,然後像這樣加載到Latex中)。
如果我沒有正確調整 pdf/圖像頁面的寬度,我最終會在章節開頭出現一個空白頁面。所以我花了很多時間,手動調整圖像寬度,使其足夠小,以擺脫章節之前的空白頁面。
不僅如此,如果我從信紙尺寸更改為法定尺寸,則不需要所有這些更改。
我想問是否有一種自動方法,可以找到 pdf 頁面或要載入的圖像使用的寬度,這樣就不會產生空白頁面。
此案例始終位於新章節的首頁。這是我的意思的 MWE。
\documentclass[11pt]{report}%
\usepackage[demo]{graphicx}
\usepackage[letterpaper]{geometry}
%\usepackage[legalpaper]{geometry}
\begin{document}
Some text here
Some text here
Some text here
Some text here
\chapter{one}
\includegraphics[width=0.9\textwidth,height=.9\textwidth]{whatever}
\includegraphics[width=0.9\textwidth,height=.9\textwidth]{whatever}
\end{document}
這是結果。第二頁是空的
更改 height=.9
為height=.85
修復它
....
\chapter{one}
\includegraphics[width=0.9\textwidth,height=.85\textwidth]{whatever}
\includegraphics[width=0.9\textwidth,height=.9\textwidth]{whatever}
....
這是結果
我明白這個問題。以及為什麼 Latex 會這樣做。該圖像有點太大,因此它在新頁面上嘗試了它,然後放棄了,以空白的浪費頁面結束。
注意:在上面的 MWE 中,我添加height=
只是為了顯示問題。在我的實際程式碼中,僅width=
使用了。但我不知道如何在不使用 的情況下在這裡顯示問題height=
。
所以我的問題是:有沒有辦法告訴 Latex 自動調整正在載入的圖片的寬度以正確的寬度,這樣就不會產生空白頁?或者一種更聰明的方法來做到這一點,而無需所有這些手動調整。
我現在所做的是運行 Latex,花費大量時間調整圖像的寬度值以刪除它們之前的空白頁面。有時我也會改變geometry
,不得不重新做這件事。自動化這個會很好。
使用 TL 2015。
答案1
巨集\getremaining
計算頁面上剩餘的垂直空間,將答案放入 length 中\vremaining
。
記得運行兩次。
\documentclass[11pt]{report}%
\usepackage[demo]{graphicx}
\usepackage[letterpaper]{geometry}
%\usepackage[legalpaper]{geometry}
\usepackage{tikzpagenodes}
\newlength{\vremaining}
\newcommand{\getremaining}%
{\begin{tikzpicture}[remember picture,overlay]
\pgfextracty{\vremaining}{\pgfpointanchor{current page text area}{south}}%
\global\vremaining=-\vremaining
\end{tikzpicture}%
\advance\vremaining by 0.6\baselineskip
\vspace*{-\baselineskip}\newline}% place above image
\begin{document}
Some text here
Some text here
Some text here
Some text here
\chapter{one}
\getremaining
\includegraphics[width=0.9\textwidth,height=\vremaining]{whatever}
\includegraphics[width=0.9\textwidth,height=.9\textwidth]{whatever}
\end{document}