# LaTeX - invalid page break for first \includegraphics in chapter

I've created chapter containing only images with caption. All images shall have fixed width (\textwidth), height is always unknown (image shall be correctly scaled).

From second image everything works fine, but first image has damaged page break, see the screenshot:

Current behaviour: chapter title is broken to next page, image itself is displayed to the same page although it doesn't fit.

Expected behaviour: chapter title stays on the first page, image is displayed to next page if it doesn't fit the previous.

Interesting is that for further images it works - if image doesn't fit, it's rendered correctly to following page.

I've tried to fix it using additional ~\newline before first image, but it still provides wrong result:

Full code:

\documentclass[a4paper]{book}

\usepackage{fontspec}

\usepackage{polyglossia}
\setmainlanguage{czech}

\usepackage{ulem}
\usepackage{spverbatim}
\usepackage[unicode]{hyperref}
\def\do#1{\appto\UrlSpecials{\do#1{\mathchar#1 \mskip 0mu plus 1mu\penalty100\relax}}}
\do\-\do\/\do\0\do\1\do\2\do\3\do\4\do\5\do\6\do\7\do\8\do\9\do\a\do\b\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j\do\k\do\l\do\m\do\n\do\o\do\p\do\q\do\r\do\s\do\t\do\u\do\v\do\w\do\x\do\y\do\z\do\A\do\B\do\C\do\D\do\E\do\F\do\G\do\H\do\I\do\J\do\K\do\L\do\M\do\N\do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V\do\W\do\X\do\Y\do\Z
\usepackage[]{graphicx}
\usepackage{grffile}
\usepackage{color}

\usepackage{wrapfig}
\usepackage{float}
\usepackage{hologo}

\usepackage{pdfpages}

\usepackage{needspace}
\intextsep=0pt

\makeatletter
\renewcommand{\l@section}{\@dottedtocline{1}{1.5em}{2.6em}}
\renewcommand{\l@subsection}{\@dottedtocline{2}{4.0em}{3.6em}}
\renewcommand{\l@subsubsection}{\@dottedtocline{3}{7.4em}{4.8em}}
\makeatother

\begin{document}
\chapter{Chapter}
\section{Section}
\begin{figure}[H]
\centering
\phantomsection\label{ID_FIL_DISPLAY_DOC_0}
\rule{\textwidth}{1.41\textwidth}
\caption{\hyperref[ID_FIL_DISPLAY_DOC_0]{Dokument~9999}}
\end{figure}
\begin{figure}[H]
\centering
\phantomsection\label{ID_FIL_DISPLAY_DOC_1}
\rule{\textwidth}{0.61\textwidth}
\caption{\hyperref[ID_FIL_DISPLAY_DOC_1]{Dokument~9999}}
\end{figure}
\begin{figure}[H]
\centering
\phantomsection\label{ID_FIL_DISPLAY_DOC_2}
\rule{\textwidth}{1.41\textwidth}
\caption{\hyperref[ID_FIL_DISPLAY_DOC_2]{Dokument~9999}}
\end{figure}
\begin{figure}[H]
\centering
\phantomsection\label{ID_FIL_DISPLAY_DOC_3}
\rule{\textwidth}{1.3\textwidth}
\caption{\hyperref[ID_FIL_DISPLAY_DOC_3]{Dokument~9999}}
\end{figure}
\begin{figure}[H]
\centering
\phantomsection\label{ID_FIL_DISPLAY_DOC_4}
\rule{\textwidth}{1.5\textwidth}
\caption{\hyperref[ID_FIL_DISPLAY_DOC_4]{Dokument~9999}}
\end{figure}

\end{document}


Question is simple: how to display first image in chapter correctly? Solution shall be universal - for tall images which don't fit to page together with chapter title and for wide images which fit to the same page (so forcing page break doesn't help, height of images is unknown).

• the whole reason that figures are normally floating environments is to help with page breaking, but you have use [H] so disabled that mechanism and not allowed latex to adjust the figure positions. – David Carlisle Jan 1 at 21:26
• all warnings about bad page breaks go if you change every [H] to [htp]` – David Carlisle Jan 1 at 21:27
• @David Carlisle: it looks better with [htp], but new issue has arised: images are vertically centered. How to draw them from the top of page? – Joseph Jan 1 at 21:40
• Solution works fine, thank you – Joseph Jan 2 at 21:09