I'm implementing gallery of scanned documents and I have issues with using \figure + \includegraphics, see the screenshot below:
1) [violet comment] caption of current image and following image are (usually, see issue below) rendered over each other
2) [violet comment] space between caption of current image and following image is unpredictable - in most cases caption and following image are glued together, but sometimes extra line is inserted (this is expected behaviour for every image)
3) [blue comment] space between image and caption belonging to this image is to big
4) [red comment] unexpected page breaks are inserted in the middle of the page although there is still enough space - this issue is really critical
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[section]{placeins}
\usepackage{hologo}
\usepackage{pdfpages}
\usepackage{needspace}
\intextsep=0pt
\DeclareTextFontCommand{\mytexttt}{\ttfamily\hyphenchar\font=45\relax}
\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}}
\setlength{\@fptop}{0pt}
\setlength{\@fpbot}{0pt plus 1fil}
\makeatother
\begin{document}
\phantomsection\label{ID_FIL_DISPLAY_DOC_507}
\begin{figure}[htp]
\centering
\rule{\textwidth}{0.231\textwidth}
\caption{\hyperref[ID_FIL_USAGELIST_DOC_507]{Dokument~508}}
\end{figure}
\FloatBarrier % Prevents error Too many unprocessed floats
\phantomsection\label{ID_FIL_DISPLAY_DOC_508}
\begin{figure}[htp]
\centering
\rule{\textwidth}{0.089\textwidth}
\caption{\hyperref[ID_FIL_USAGELIST_DOC_508]{Dokument~509}}
\end{figure}
\FloatBarrier % Prevents error Too many unprocessed floats
\phantomsection\label{ID_FIL_DISPLAY_DOC_509}
\begin{figure}[htp]
\centering
\rule{\textwidth}{0.105\textwidth}
\caption{\hyperref[ID_FIL_USAGELIST_DOC_509]{Dokument~510}}
\end{figure}
\FloatBarrier % Prevents error Too many unprocessed floats
\phantomsection\label{ID_FIL_DISPLAY_DOC_510}
\begin{figure}[htp]
\centering
\rule{\textwidth}{0.059\textwidth}
\caption{\hyperref[ID_FIL_USAGELIST_DOC_510]{Dokument~511}}
\end{figure}
\FloatBarrier % Prevents error Too many unprocessed floats
\phantomsection\label{ID_FIL_DISPLAY_DOC_511}
\begin{figure}[htp]
\centering
\rule{\textwidth}{0.264\textwidth}
\caption{\hyperref[ID_FIL_USAGELIST_DOC_511]{Dokument~512}}
\end{figure}
\FloatBarrier % Prevents error Too many unprocessed floats
\phantomsection\label{ID_FIL_DISPLAY_DOC_512}
\begin{figure}[htp]
\centering
\rule{\textwidth}{0.154\textwidth}
\caption{\hyperref[ID_FIL_USAGELIST_DOC_512]{Dokument~513}}
\end{figure}
\FloatBarrier % Prevents error Too many unprocessed floats
\phantomsection\label{ID_FIL_DISPLAY_DOC_513}
\begin{figure}[htp]
\centering
\rule{\textwidth}{0.329\textwidth}
\caption{\hyperref[ID_FIL_USAGELIST_DOC_513]{Dokument~514}}
\end{figure}
\FloatBarrier % Prevents error Too many unprocessed floats
\end{document}
Could you please help me to find solutions
1) how to force space between caption and following image?
2) how to force always the same space between caption and following image?
3) how to decrease space between image and its caption (I have thousands images in document, cca 4000 pages, and because at the end it will be printed to paper, every removed page from document is useful)?
4) how to fix unwanted page breaks in the middle of the page (of course, no image or caption shall overflow below text area, but I expect whole space on page shall be used if image + caption fits to it)?
Maybe \figure + \includegraphics is not convenient for image galleries?
figure
environments, or equivalently use the[H]
option from the float package, you could then remove the floatbarrier commands (that are forcing page breaks).