Page LayoutBlank Pages before and after chapters

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
cyanidebaby
Posts: 11
Joined: Tue Feb 07, 2017 1:56 pm

Blank Pages before and after chapters

Post by cyanidebaby »

Hello,

(Apologies for pasting this huge chunk of code, but since I can't pin point where the problem lies, I thought it best to show you the whole thing)

This code (which is very much a work-in-progress) seems to generate empty pages before and after my chapters.

Case in point, from the top, we have a "Preamble", followed by an "Introduction", followed by a blank page and the first chapter. The first chapter should appear where the first blank page pops up though.
The same situation occurs later, between the end of Chapter 1 and the beginning of Chapter 2: indeed, here again, there's a blank page where Chapter 2 should be. And a final blank-page appears after Chapter 2.

I also noticed that "List of Tables" keeps appearing in the headers above the "Preamble", "Introduction" and first blank-page pages. I mention this here as I have a feeling that it's all related to the same issue: my code seems to not obeying my \clearpage commands to start afresh.

Could the issues I describe above be helped by segmenting my document and start using the \include command to call-in individual latex files, for each chapter, etc.?

Any help (and explanation) would be much welcome.
Thank you for your time.

- Alex

Code: Select all

% PREAMBLE

\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{geometry}
\usepackage[english]{babel}
\usepackage{tocloft}
\usepackage[nottoc]{tocbibind}
\usepackage{hyperref}
\usepackage{geometry}
\usepackage{multicol}
\usepackage{babel}
\usepackage{graphicx}
\graphicspath{ {h:/} }
\usepackage{enumitem}
\usepackage{marginnote}
\usepackage[document]{ragged2e}
\usepackage{eso-pic}
\usepackage{ifthen}
\usepackage{tikz}
\usepackage{color}
%\usepackage{showframe}
\usepackage{blindtext}
\usepackage{lipsum}

\setlength{\columnsep}{8mm}

%Table of Content depth
\geometry{verbose}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{5}
\setlength{\parindent}{0pt}

%Hyperlinks for TOC
\makeatletter
\hypersetup{
	colorlinks,
	citecolor=black,
	filecolor=black,
	linkcolor=black,
	urlcolor=black
}

\makeatother

%Formating Document per Pto-M-cook
\geometry{
	a4paper,
	total={21.59cm,27.94cm},
	top=2.8cm,
	bottom=2.1cm,
	inner=1.91cm,
	outer=6.68cm,
	marginparwidth=4cm,
	marginparsep=0.8cm
}

%\renewcommand{\cfttoctitlefont}{\hfil \Huge}

% FRONTMATTER STARTS

\begin{document}

\frontmatter

\title{A Fantastic Title}
\author{Author's Name}

\begingroup

\oddsidemargin=0.5\dimexpr\paperwidth-\textwidth-2in\relax
\evensidemargin=\oddsidemargin

\newpage
\maketitle
\newpage

\newpage
\tableofcontents
\newpage

\newpage
\listoftables
\newpage

\newpage
\phantomsection
\addcontentsline{toc}{section}{Preface}
\section*{Preface}
\blindtext
\newpage


\newpage
\phantomsection
\addcontentsline{toc}{section}{Introduction}
\section*{Introduction}
\blindtext
\newpage

\clearpage
\endgroup
\clearpage

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Following is the code used to create vertical bars between text body and margin

\def\bottommargin{\paperheight - \topmargin - \textheight - \headheight - \headsep - 1in - \voffset}
\def\toptotalheight{\paperheight - \topmargin - \headheight - \headsep - 1in - \voffset}
\def\leftlength{
	\evensidemargin - 0.5*\marginparsep
	+ 1in
	+ \hoffset
}
\def\rightlength{\paperwidth
	- \evensidemargin + 0.5*\marginparsep
	- 1in - \hoffset}

\makeatletter
\newcommand{\nomarginbar}{\let\ESO@HookIIBG\@empty}
\makeatother

\newcommand{\thisisfullsize}{\path (0,0) --  (\paperwidth,\paperheight);}

\newcommand\LeftBar{%
	\put(0,0){%
		\parbox[b][\paperheight]{\paperwidth}{%
			\vfill
			\centering
			\begin{tikzpicture}
			\thisisfullsize
			\color{lightgray}
			\draw[line width=1pt] (\leftlength,\bottommargin) -- (\leftlength,\toptotalheight);
			\end{tikzpicture}
			\vfill
}}}

\newcommand\RightBar{% 
	\put(0,0){%
		\parbox[b][\paperheight]{\paperwidth}{%
			\vfill
			\centering
			\begin{tikzpicture}
			\thisisfullsize
			\color{lightgray}
			\draw[line width=1pt] (\rightlength,\bottommargin) -- (\rightlength,\toptotalheight);
			\end{tikzpicture}
			\vfill
}}}

%%% Use this in two-side documents
\AtBeginShipout{%
	\ifthenelse{\isodd{\value{page}}}%
	{\AddToShipoutPictureBG*{\LeftBar}%
	}%
	{\AddToShipoutPictureBG*{\RightBar}%
	}%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% MAINMATTER STARTS

\mainmatter

\chapter{The First Chapter}

\begin{multicols*}{2}

\section{THE FIRST SECTION HAS A REALLY LONG AND THEREFORE PROBLEMATIC TITLE}
\blindtext

And now this table:

\begin{table*}
	\centering
	\begin{tabular}{r|c|c|l}
	\hline
	Information & Information & Information & Information\tabularnewline \hline  Information & Information & Information & Information\tabularnewline Information & Information & Information & Information\tabularnewline Information & Information & Information & Information\tabularnewline Information & Information & Information & Information\tabularnewline Information & Information & Information & Information\tabularnewline
	\hline
	\end{tabular}
	\caption{Important Data}
\end{table*}

\marginnote{\lipsum[75]}[0cm]

\blindtext

\subsection{The Subsection}
\blindtext

And now I'm going to list a list of listed things:
\begin{enumerate}[noitemsep,topsep=0pt,parsep=0pt,partopsep=0pt]
	\item \blindtext
	\item \blindtext
	\item \blindtext
\end{enumerate}
\blindtext

\subsubsection{A Subsubsection}
\blindtext

\marginnote{\lipsum[75]}[0cm]

\blindtext

%To clear empty page before Chapter
%\let\cleardoublepage\clearpage

\chapter{The Second Chapter}

\section{The Second Proper Section}
\blindtext

The image should appear right after this:

%\includegraphics*{universe}

And now, more text to see how this works.

\subsection{The Second Subsection}
\blindtext
	
\subsubsection{A Second Subsubsection}
\blindtext
	
\marginnote{\lipsum[75]}[0cm]
	
\blindtext

\end{multicols*}

% BACKMATTER STARTS

%\appendix

\backmatter

%\printindex

\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Blank Pages before and after chapters

Post by Stefan Kottwitz »

Hi Alex,

welcome to the forum!

Segmenting the document and using \include for chapters can make working easier. But it is not necessary to fix the issue here.

Here, after the introduction section, you have multiple page breaks - remove them or comment them out (\newpage, \clearpage)

Code: Select all

\newpage
\phantomsection
\addcontentsline{toc}{section}{Introduction}
\section*{Introduction}
\blindtext
\newpage
 
\clearpage
\endgroup
\clearpage
Chapters start at right hand pages by default. So they start at odd numbered pages (1, 3, 5, 7, ..). If the text before ends at page 5, the next chapter starts at page 7. You can add the openany option to the document class if you would like to suppress this, or just for testing now: \documentclass[openany]{book}

The \mainmatter command has an implicit \cleardoublepage. So it contains a page break and possibly inserts an empty page so the next page starts on a right hand side. Comment out \mainmatter as additional test. Then, together with openany, there should not be an empty page before the first chapter.

Stefan
LaTeX.org admin
cyanidebaby
Posts: 11
Joined: Tue Feb 07, 2017 1:56 pm

Blank Pages before and after chapters

Post by cyanidebaby »

Hi Stefan.

Thank you very much for your reply.

Your suggestions work ... mostly.

\documentclass[openany]{book} does the trick ... in part (I totally forgot about the odd/even way pages are handled in the book class. Thank you for that.).

Indeed, as often is the case with LaTex (at least, in my very limited experience), one solution to a problem leads to additional or unintended problems.
Case in point, the [openany] solution: the blank page that used to appear after Chapter 2 is now gone, which is great. But the blank page between "Introduction" and "Chapter 1" is still there.

So I commented out \mainmatter, which gets rid of the blank page before "Chapter 1" (yay!), but the numerals for the whole document are now Roman Numerals ( :lol: ), and the line which I've positioned between the text body and the margin now starts on the page that follows the first Chapter 1 page. Oops.
My head is spinning.

Goes without saying that I put \mainmatter the way it was.

Then I got rid of the many unneeded \newpage page breaks.
Removing too many of them sticks the "Preamble" and "Introduction" to the "List of Tables" though, so I had to keep some.

So, the result, as of right now is: the blank page after Chapter 2 is gone, but the blank page before Chapter 1 is still there.

Code: Select all

% PREAMBLE

\documentclass[openany]{book}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{geometry}
\usepackage[english]{babel}
\usepackage{tocloft}
\usepackage[nottoc]{tocbibind}
\usepackage{hyperref}
\usepackage{geometry}
\usepackage{multicol}
\usepackage{babel}
\usepackage{graphicx}
\graphicspath{ {h:/} }
\usepackage{enumitem}
\usepackage{marginnote}
\usepackage[document]{ragged2e}
\usepackage{eso-pic}
\usepackage{ifthen}
\usepackage{tikz}
\usepackage{color}
%\usepackage{showframe}
\usepackage{blindtext}
\usepackage{lipsum}

\setlength{\columnsep}{8mm}

%Table of Content depth
\geometry{verbose}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{5}
\setlength{\parindent}{0pt}

%Hyperlinks for TOC
\makeatletter
\hypersetup{
	colorlinks,
	citecolor=black,
	filecolor=black,
	linkcolor=black,
	urlcolor=black
}

\makeatother

%Formating Document per Pto-M-cook
\geometry{
	a4paper,
	total={21.59cm,27.94cm},
	top=2.8cm,
	bottom=2.1cm,
	inner=1.91cm,
	outer=6.68cm,
	marginparwidth=4cm,
	marginparsep=0.8cm
}

%\renewcommand{\cfttoctitlefont}{\hfil \Huge}

% FRONTMATTER STARTS

\begin{document}
	
\frontmatter
	
\title{A Fantastic Title}
\author{Author's Name}
	
\begingroup
	
\oddsidemargin=0.5\dimexpr\paperwidth-\textwidth-2in\relax
\evensidemargin=\oddsidemargin
	
\maketitle
	
\tableofcontents
	
\newpage
\listoftables
\newpage
	
\phantomsection
\addcontentsline{toc}{section}{Preface}
\section*{Preface}
\blindtext
\newpage
	
\phantomsection
\addcontentsline{toc}{section}{Introduction}
\section*{Introduction}
\blindtext

\clearpage
\endgroup
\clearpage
	
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Following is the code used to create vertical bars between text body and margin
	
\def\bottommargin{\paperheight - \topmargin - \textheight - \headheight - \headsep - 1in - \voffset}
\def\toptotalheight{\paperheight - \topmargin - \headheight - \headsep - 1in - \voffset}
\def\leftlength{
	\evensidemargin - 0.5*\marginparsep
		+ 1in
		+ \hoffset
	}
\def\rightlength{\paperwidth
	- \evensidemargin + 0.5*\marginparsep
	- 1in - \hoffset}
	
\makeatletter
\newcommand{\nomarginbar}{\let\ESO@HookIIBG\@empty}
\makeatother
	
\newcommand{\thisisfullsize}{\path (0,0) --  (\paperwidth,\paperheight);}
	
\newcommand\LeftBar{%
	\put(0,0){%
		\parbox[b][\paperheight]{\paperwidth}{%
			\vfill
			\centering
			\begin{tikzpicture}
			\thisisfullsize
			\color{lightgray}
			\draw[line width=1pt] (\leftlength,\bottommargin) -- (\leftlength,\toptotalheight);
			\end{tikzpicture}
			\vfill
}}}
	
\newcommand\RightBar{% 
	\put(0,0){%
		\parbox[b][\paperheight]{\paperwidth}{%
			\vfill
			\centering
			\begin{tikzpicture}
			\thisisfullsize
			\color{lightgray}
			\draw[line width=1pt] (\rightlength,\bottommargin) -- (\rightlength,\toptotalheight);
			\end{tikzpicture}
			\vfill
}}}
	
%%% Use this in two-side documents

\AtBeginShipout{%
	\ifthenelse{\isodd{\value{page}}}%
	{\AddToShipoutPictureBG*{\LeftBar}%
	}%
	{\AddToShipoutPictureBG*{\RightBar}%
	}%
}
	
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	
% MAINMATTER STARTS
\mainmatter

\chapter{The First Chapter}
	
\begin{multicols*}{2}
		
\section{THE FIRST SECTION HAS A REALLY LONG AND THEREFORE PROBLEMATIC TITLE}
\blindtext

And now this table:
		
\begin{table*}
	\centering
	\begin{tabular}{r|c|c|l}
		\hline
		Information & Information & Information & Information\tabularnewline \hline  Information & Information & Information & Information\tabularnewline Information & Information & Information & Information\tabularnewline Information & Information & Information & Information\tabularnewline Information & Information & Information & Information\tabularnewline Information & Information & Information & Information\tabularnewline
		\hline
	\end{tabular}
	\caption{Important Data}
\end{table*}
		
\marginnote{\lipsum[75]}[0cm]

\blindtext
		
\subsection{The Subsection}
\blindtext
		
And now I'm going to list a list of listed things:
\begin{enumerate}[noitemsep,topsep=0pt,parsep=0pt,partopsep=0pt]
	\item \blindtext
	\item \blindtext
	\item \blindtext
\end{enumerate}
\blindtext
		
\subsubsection{A Subsubsection}
\blindtext
		
\marginnote{\lipsum[75]}[0cm]
		
\blindtext

\chapter{The Second Chapter}
		
\section{The Second Proper Section}
\blindtext

The image should appear right after this:

%\includegraphics*{universe}
		
And now, more text to see how this works.
		
\subsection{The Second Subsection}
\blindtext
		
\subsubsection{A Second Subsubsection}
\blindtext
		
\marginnote{\lipsum[75]}[0cm]
		
\blindtext
		
\end{multicols*}
	
% BACKMATTER STARTS
	
%\appendix
	
\backmatter
	
%\printindex
	
\end{document}
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Blank Pages before and after chapters

Post by Stefan Kottwitz »

Instead of \mainmatter you could use

Code: Select all

\makeatletter
\@mainmattertrue
\pagenumbering{arabic}}
\makeatother
Basically it's switching to arabic numbers and starting with 1, but I added setting the internal variable for being in the main matter too.

Stefan
LaTeX.org admin
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Blank Pages before and after chapters

Post by Johannes_B »

The blank page is needed and correct there. What Stefan posted may seem to work, but set the outer margin to a value of 8 cm (which is extreme). Also add the showframe option for package geometry. An odd page is always a right hand page.

The command \pagenumbering needs to have a \cleardoublepage in front, and in my opinion that should be defined within that command so a user doesn't have to care.

Say, do you want to print your document as a book (left and right are printed on) or mor like a school report or thesis? In that case, maybe try oneside.

EDIT: Upon a closer look, the template isn't very good. :-/
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
cyanidebaby
Posts: 11
Joined: Tue Feb 07, 2017 1:56 pm

Blank Pages before and after chapters

Post by cyanidebaby »

Thank you both for your replies.

Stefan:
I've been getting interesting results with twocolumn instead of with multicol, so I'm going to go ahead and explore that a little. If it still doesn't work, I'll move one and find another solution.

Johannes:
For print?
At this point, it looks like the book is never going to be printed. Still, I would like to keep that option opened.

The blank pages?
They are indeed part of the book documentclass, but I'd like to get rid of them, as the book will be mostly read/used as a PDF ... and blank pages in PDFs are not great.

This template is bad:
Well, I actually agree ... in part. Indeed, as you've realized, the book is not a novel. It's a sort of encyclopedic guide, part history, part geography and part culture. It's long, with lots of text (close to 400 single spaced pages), side notes on almost every page, few illustrations but quite a few tables and charts (some small, some full page), and a long, very detailed index (and probably an appendix too).
Because the book is so full of at times tough to digest information, I thought that the text would benefit from being presented in a template with a wide margin (for the many side notes; not a fan of footnotes), and a two column body to help reader with the text (some pages will be formatted as a single column though, on a case to case basis).

This WIP template you've looked at is based on a book that was published a little while back (see attached image).
Yes, it's not the latest in great book design, but it's one that contains the sort of info the book I'm working on contains.
If you have a ready-made template in mind for that sort of book, please, let me know. I'd love to take a look at it, which would save me time!

Anyway, I appreciate your useful straight forward comment.
Attachments
Capture.PNG
Capture.PNG (158.17 KiB) Viewed 43941 times
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Blank Pages before and after chapters

Post by Johannes_B »

Imagine: if this is a pdf which will be read as a pdf, one page, another page, anothe page, another page. Do you need the margin notes to flip sides?

If this is going to be printed, you have to care about the margin note beeing on this or that side. But only if it is printed, which is (i am assunimg) in the future.

You cannot compare a printed document with an ebook :-)
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
cyanidebaby
Posts: 11
Joined: Tue Feb 07, 2017 1:56 pm

Blank Pages before and after chapters

Post by cyanidebaby »

All very good points. Yes.

Back to my cauldron then.
Post Reply