I'm trying to insert some sidewaysfigure
environments between segments of text. The output should be like
- Title Page
- Text (ends about halfway down the page)
- Sideways Figure
- Sideways Figure
- Text
The problem I'm having is there's an extra blank page inserted before the figures and at the end of the output, like this
- Title Page
- Text
- Blank Page
- Sideways Figure
- Sideways Figure
- Text
- Blank Page
here's my code:
%--- document type, don't touch this ------
\documentclass[a4paper,11pt]{article}
%--- packages used, may need to add to this -----
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage[top=1in, bottom=1.25in, left=1.25in, right=1.25in]{geometry}
\usepackage{pdflscape}
\usepackage{graphicx}
\usepackage{rotating}
\usepackage[labelfont=bf]{caption}
\usepackage{float}
%---- Change these to reflect your experiment -----
\providecommand{\expname}{Experiment Name}%Name of the Experiment
\providecommand{\expdate}{Experiment Date}%Date Experiment was done
%---- This is the definition of \pefig, do not alter it ------
\newcommand{\pefig}[3]{
\let\cleardoublepage\clearpage
\begin{sidewaysfigure}[ht]
\pagestyle{empty}
\centering
\includegraphics[width=0.9\linewidth,keepaspectratio]{#1}
\caption{#2}
\label{#3}
\end{sidewaysfigure}
}
%--- these commands control the header, don't touch 'em -------
\setlength{\headheight}{25.3pt}
\renewcommand{\headrulewidth}{0pt}
\lhead{\iffloatpage{}{Your Name}}
\chead{\iffloatpage{}{PEGN 308: Reservoir Rock Properties\\
\expname}}
\rhead{\iffloatpage{}{\thepage\\\expdate}}
\cfoot{}
%--- You can make this whatever you want, it doesn't affect anything, just names it on Overleaf
\title{Paper Title}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Actual Content %%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\pagestyle{empty}
\topskip0pt
\vspace*{\fill}
\vspace*{-15pt}
\begin{center}
PEGN 308: Reservoir Rock Properties\\
\expname\\
\textbf{Your Name}\\
Section X Group X1\\
Instructor:\\
Al Sami\\
Lab Group Members:\\
Their\\
Names\\
Here\\
\pageref{LastPage} pages\\
\expdate
\end{center}
\vspace*{\fill}
\newpage
%--- Report ------
\setcounter{page}{1}
\pagestyle{fancy}
a buncha text here
\clearpage
%blank page appears here for some reason
%--- Figures -----
%Syntax is: \pefig{filename}{Caption}{Label}
\pefig{Sample.jpg}{Sample Figure}{fig:sample1}
\pefig{Sample.jpg}{Sample Figure}{fig:sample2}
\clearpage
a bunch more text here
%Blank page here too
\end{document}
The trailing blank page was actually there before I inserted the images, I think it has something to do with the way I made my title page
Please help, I think my problems stem from a poor understanding of \newpage
and \clearpage
EDIT: For the record, all of those comments are from me to the eventual user, a student in PEGN 308, so when something says "don't modify this" that absolutely doesn't apply to me.
Best Answer
The immediate problem is caused by the global redefinition
which, apart from anything else,
geometry
knows nothing about.Removing this removes the additional pages. Wrapping the title page code in
titlepage
also works because it limits the scope of the setting. I would recommend something like this:Usually it is bad to end lines with
\\
but it is OK when text is centred as it is equivalent to ending the paragraph.However, definitions like the following
are problematic because they insert spurious spaces. In many cases, this won't matter because the content is sandwiched by page breaks anyway. But in some cases, it will matter.
A line ending is a space.
is equivalent to
To avoid this in macro definitions, you can comment line endings. For example,
Moreover, redefining
\cleardoublepage
is pointless here. You are typesetting a one-sided article.Are pages with figures supposed to have page numbers? If so, setting the page style to empty is incorrect. If not, setting the page style in this way does nothing. That is.
should either be deleted (for page numbers) or changed to
(for no page numbers on these pages).
Setting
ht
for asidewaysfigure
makes little sense. So I'd drop that, too, and use something likeThen the result is