LaTeX 图形没有用 FloatBarrier 填充整个页面(高度空间)

LaTeX 图形没有用 FloatBarrier 填充整个页面(高度空间)

我遇到了一个问题,我甚至无法想象如何向谷歌提问。可能是我的文档结构出了问题,现在它无法正常工作。

首先,我需要精确地放置图形,因此我在每个图像命令中都添加了 \FloatBarrier:

\newcommand{\image}[4][40mm]{
\begin{figure}[h]%
\centering%
\fcolorbox{frameColor}{white}{\includegraphics[width=\textwidth, height = #1, keepaspectratio]{#2}}
\caption{#3}%
\label{#4}
\end{figure}%
\FloatBarrier
}

在大多数情况下,它都能正常工作。下图中有一个具体案例:

缩小图像创建空白空间

LaTeX 代码如下:

Klikamy znaczek plusa, który widoczny jest w dolnej części naszego bloczka \textbf{if}. Zostanie wtedy dodane miejsce na drugi warunek, oznaczony jako \textbf{else if}.

\image[59mm]{cz3/19}{Nowa sekcja else if w instrukcji warunkowej}{fig:fig3_15}

Drugi warunek wypełniamy analogicznie do pierwszego. Zmieniamy tylko od razu wartości liczbowe. W pierwszym warunku wpisujemy 200, a w drugim 500. Dodajemy też bloczki włączające i wyłączające diodę na module podłączonym do wyjścia P1.

\image[71mm]{cz3/20}{Ostateczna wersja programu z rozbudowanym warunkiem}{fig:fig3_16}

\newpage

Całość interpretujemy następująco:

\begin{enumerate}
\item Odczytaj wartość z wejścia P0 i sprawdź, czy jest mniejsza od liczby 200.

我添加了 \newpage,因为底部出现了一些文本。看到这个空白区域,我想放大图像以填充它。但如果我只将尺寸增加 1 毫米,图像就会移动到下一页,就好像它太大了一样……

将尺寸从 71 改为 72 弄乱了

构建这个结构是一个反复试验的过程,所以可能会很混乱……我注意到这种行为(可能)只发生在左侧页面上。请帮帮我 :)

%----------------------------------------------------------------------------------------
%   INFORMATIONS
%----------------------------------------------------------------------------------------
% A%: BRUTTO PAGE SIZE: 154x216 mm (+6) / B5: 182x256
% NETTO PAGE SIZE: 148x210 mm       / B5: 176x250
% BLEED MARGIN: 3mm
% LAYOUT A5
%WARNING! zmien tez w main

%----------------------------------------------------------------------------------------
%   PACKAGES AND CONFIGURATIONS
%----------------------------------------------------------------------------------------
\usepackage[top=20mm,bottom=20mm,outer=16mm,inner=24mm,papersize={169mm,234mm}]{geometry} % Page B5 with 2mm bleed showframe
% \usepackage[top=20mm,bottom=20mm,outer=20mm,inner=25mm,papersize={182mm,256mm}]{geometry} % Page A5 with 3mm bleed
% \usepackage{graphicx} % Required for including pictures
\usepackage[export]{adjustbox}
\graphicspath{{Pictures/}} % Specifies the directory where pictures are stored
\usepackage{pdfpages}
%\footskip=0pt
%\flushbottom
\usepackage{showframe}

\usepackage[hang]{footmisc}
%\renewcommand{\footnotelayout}{\hspace{1mm}}
\renewcommand{\hangfootparindent}{1em}% Indentation for 2nd etc. paragraphs in footnotes which cosists of more than one paragraph
\renewcommand{\hangfootparskip}{3pt}% Vertical space between paragraphs in multiparagraph footnotes
\renewcommand{\footnotemargin}{0.00001pt}% Setting left margin; this is the smallest value I can get to have second etc. lines indented to footnote number; zero put indentation to some positive value, and negative values do not help actually
\renewcommand{\footnotelayout}{\hspace{1em}}% Here you can modify the spacing between the footnote number and the text of footnote; keep this value and \hangfootparindent value the same


%----------------------------------------------------------------------------------------
%   CAPTION AND FIGURES
%----------------------------------------------------------------------------------------
\usepackage[skip=6pt, font=small, justification=centering, labelfont=it, textfont=it]{caption}
\usepackage[labelformat=empty]{subcaption}
\DeclareCaptionSubType*{figure}
\renewcommand\thesubfigure{Rys. \thefigure\alph{subfigure}:}
%\renewcommand\thesubfigure{(Rys. \thefigure\alph{subfigure})}
\DeclareCaptionLabelFormat{opening}{#2}
\captionsetup[subfigure]{labelformat=opening}
%\renewcommand{\figurename}{Fig.}
%\usepackage[figurename=Fig.]{caption}

\usepackage{qrcode}
% \usepackage{pst-barcode}

\usepackage{lipsum}

% Rys.
% \DeclareCaptionSubType*{figure}
% \renewcommand\thesubfigure{(\alph{subfigure})}
% \DeclareCaptionLabelFormat{opening}{\thefigure#2}
% \captionsetup[subfigure]{labelformat=opening}

\usepackage{float}
\usepackage{placeins}
\usepackage{siunitx}
\sisetup{detect-family=true, detect-display-math = true}
%\sisetup{detect-weight=true, detect-family=true, detect-display-math = true}

\usepackage{tikz} % Required for drawing custom shapes
\usepackage{amsthm}
\usepackage{amsmath,amsfonts,amssymb} % For math equations, theorems, symbols, etc

\usepackage{ulem}
% \usepackage[euler]{textgreek}

% \usepackage[polish]{babel} % English language/hyphenation
% \usepackage[english]{babel} % English language/hyphenation

\usepackage[utf8]{inputenc}
\usepackage[autostyle]{csquotes}
\DeclareQuoteAlias{dutch}{polish}
\usepackage[T1]{fontenc}
\usepackage{babel}

% \usepackage[utf8]{inputenc} % Required for including letters with accents
% \usepackage{polski}
% \usepackage[T1]{fontenc} % Use 8-bit encoding that has 256 glyphs
% \usepackage[autostyle]{csquotes}
% \DeclareQuoteAlias{dutch}{polish}

\DeclareMathSymbol{,}{\mathpunct}{letters}{"3B}
\DeclareMathSymbol{.}{\mathord}{letters}{"3B}
\DeclareMathSymbol{\decimal}{\mathord}{letters}{"3A}

\usepackage{enumitem} % Customize lists
\setlist{nolistsep} % Reduce spacing between bullet points and numbered lists
%\let\labelitemi\labelitemi
%\renewcommand\labelitemii{\textbullet}
%\renewcommand\labelitemii{\textperiodcentered}
\renewcommand\labelitemii{$\circ$}
\renewcommand\labelitemiii{\tiny$\blacksquare$}
%\renewcommand\labelitemiii{\LARGE$\cdot$}
%\newcommand\labelitemi{\textbullet}% bullet

%\Huge
%\huge
%\LARGE
%\Large
%\large
%\normalsize (default)
%\small
%\footnotesize
%\scriptsize
%\tiny

\usepackage{booktabs} % Required for nicer horizontal rules in tables
\usepackage{xcolor} % Required for specifying colors by name
% \usepackage{dirtytalk}
\usepackage{framed}
\usepackage[most]{tcolorbox}
\fboxsep=0mm%padding thickness
\fboxrule=1pt%border thickness
\input{colours.tex}

%----------------------------------------------------------------------------------------
%   FONTS
%----------------------------------------------------------------------------------------
\usepackage{avant} % Use the Avantgarde font for headings
\usepackage{mathptmx} % Use the Adobe Times Roman as the default text font together with math symbols from the Sym­bol, Chancery and Com­puter Modern fonts
\usepackage{microtype} % Slightly tweak font spacing for aesthetics

\frenchspacing
\usepackage{parskip}

%----------------------------------------------------------------------------------------
%   BIBLIOGRAPHY AND INDEX
%----------------------------------------------------------------------------------------
\usepackage{csquotes}
\usepackage[style=alphabetic,citestyle=numeric,sorting=nyt,sortcites=true,autopunct=true,autolang=hyphen,hyperref=true,abbreviate=false,backref=true,backend=biber,defernumbers=true]{biblatex}
\addbibresource{bibliography.bib} % BibTeX bibliography file
\defbibheading{bibempty}{}

\usepackage{calc} % For simpler calculation - used for spacing the index letter headings correctly
\usepackage{makeidx} % Required to make an index
\makeindex % Tells LaTeX to create the files required for indexing

%----------------------------------------------------------------------------------------
%   MAIN TABLE OF CONTENTS
%----------------------------------------------------------------------------------------
\usepackage{titletoc} % Required for manipulating the table of contents
\contentsmargin{0cm} % Removes the default margin

% Chapter text styling
\titlecontents{chapter}[1.25cm] % Indentation
{\addvspace{12pt}\large\sffamily\bfseries} % Spacing and font options for chapters
{\color{basecolour!60}\contentslabel[\Large\thecontentslabel]{1.25cm}\color{basecolour}} % Chapter number
{\color{basecolour}}  
{\color{basecolour!60}\normalsize\;\titlerule*[.5pc]{.}\;\thecontentspage} % Page number

% Section text styling
\titlecontents{section}[1.25cm] % Indentation
{\addvspace{3pt}\sffamily\bfseries} % Spacing and font options for sections
{\contentslabel[\thecontentslabel]{1.25cm}} % Section number
{}
{\hfill\color{black}\thecontentspage} % Page number
[]

% Subsection text styling
\titlecontents{subsection}[1.25cm] % Indentation
{\addvspace{1pt}\sffamily\small} % Spacing and font options for subsections
{\contentslabel[\thecontentslabel]{1.25cm}} % Subsection number
{}
{\ \titlerule*[.5pc]{.}\;\thecontentspage} % Page number
[]

% List of figures
\titlecontents{figure}[0em]
{\addvspace{-5pt}\sffamily}
{\thecontentslabel\hspace*{1em}}
{}
{\ \titlerule*[.5pc]{.}\;\thecontentspage}
[]

% List of tables
\titlecontents{table}[0em]
{\addvspace{-5pt}\sffamily}
{\thecontentslabel\hspace*{1em}}
{}
{\ \titlerule*[.5pc]{.}\;\thecontentspage}
[]

%----------------------------------------------------------------------------------------
%   PAGE HEADERS
%----------------------------------------------------------------------------------------
\usepackage{fancyhdr} % Required for header and footer configuration

%\newcommand*\small{%   
%\@setfontsize\small\@xpt\@xiipt 

\pagestyle{fancy}
%\renewcommand{\chaptermark}[1]{\markboth{\sffamily\normalsize\bfseries\chaptername\ \thechapter.\ #1}{}} % Chapter text font settings
%\renewcommand{\sectionmark}[1]{\markright{\sffamily\normalsize\thesection\hspace{5pt}#1}} % Section text font settings
\renewcommand{\chaptermark}[1]{\markboth{\large\bfseries\chaptername\ \thechapter.\ #1}{}} % Chapter text font settings
\renewcommand{\sectionmark}[1]{\markright{\small\thesection\hspace{5pt}#1 – https://kurs.forbot.pl/elektronika}{}} % Section text font settings
\fancyhf{} \fancyhead[LE,RO]{\sffamily\normalsize\thepage} % Font setting for the page number in the header
\fancyhead[LO]{\rightmark} % Print the nearest section name on the left side of odd pages
\fancyhead[RE]{\leftmark} % Print the current chapter name on the right side of even pages
\renewcommand{\headrulewidth}{0.5pt} % Width of the rule under the header
\addtolength{\headheight}{2.5pt} % Increase the spacing around the header slightly
\renewcommand{\footrulewidth}{0pt} % Removes the rule in the footer
\fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrulewidth}{0pt}} % Style for when a plain pagestyle is specified

% Removes the header from odd empty pages at the end of chapters
\makeatletter
\renewcommand{\cleardoublepage}{
\clearpage\ifodd\c@page\else
\hbox{}
\vspace*{\fill}
\thispagestyle{empty}
\newpage
\fi}

%----------------------------------------------------------------------------------------
%   BOXES
%----------------------------------------------------------------------------------------
\input{boxes.tex}

%----------------------------------------------------------------------------------------
%   SECTION NUMBERING IN THE MARGIN
%----------------------------------------------------------------------------------------
\makeatletter
\renewcommand{\@seccntformat}[1]{\textcolor{basecolour}{\csname the#1\endcsname}\hspace{0.5em}}%odsuniecie numeracji
%\renewcommand{\@seccntformat}[1]{\llap{\textcolor{basecolour}{\csname the#1\endcsname}\hspace{0.5em}}}%odsuniecie numeracji

\renewcommand{\section}{\@startsection{section}{1}{\z@}
{-4ex \@plus -1ex \@minus -.4ex}
{1ex \@plus.2ex }
{\normalfont\large\sffamily\bfseries}}

\renewcommand{\subsection}{\@startsection {subsection}{2}{\z@}
{-3ex \@plus -0.1ex \@minus -.4ex}
{0.5ex \@plus.2ex }
{\normalfont\sffamily\bfseries}}

\renewcommand{\subsubsection}{\@startsection {subsubsection}{3}{\z@}
{-2ex \@plus -0.1ex \@minus -.2ex}
{.2ex \@plus.2ex }
{\normalfont\small\sffamily\bfseries}}

\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}
{-2ex \@plus-.2ex \@minus .2ex}
{.1ex}
{\normalfont\small\sffamily\bfseries}}

%----------------------------------------------------------------------------------------
%   CHAPTER HEADINGS
%----------------------------------------------------------------------------------------
\newif\ifusechapterimage
\usechapterimagetrue
\newcommand{\thechapterimage}{}%
\newcommand{\chapterimage}[1]{\ifusechapterimage\renewcommand{\thechapterimage}{#1}\fi}%
\def\@makechapterhead#1{%
{\parindent \z@ \raggedright \normalfont
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.north west)
{\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north west,inner sep=0pt] at (0,0) {\ifusechapterimage\includegraphics[width=\paperwidth]{\thechapterimage}\fi};
\draw[anchor=west] (\Gm@lmargin,-7cm) node [line width=2pt,rounded corners=0pt,draw=basecolour,fill=white,fill opacity=0.9,inner sep=15pt]{\strut\makebox[22cm]{}};
\draw[anchor=west] (\Gm@lmargin+.3cm,-7cm) node {\huge\sffamily\bfseries\color{black}\thechapter. #1\strut};
\end{tikzpicture}};
\end{tikzpicture}
\else
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.north west)
{\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north west,inner sep=0pt] at (0,0) {\ifusechapterimage\includegraphics[width=\paperwidth]{\thechapterimage}\fi};
\draw[anchor=west] (\Gm@lmargin,-7cm) node [line width=2pt,rounded corners=0pt,draw=basecolour,fill=white,fill opacity=0.9,inner sep=15pt]{\strut\makebox[22cm]{}};
\draw[anchor=west] (\Gm@lmargin+.3cm,-7cm) node {\huge\sffamily\bfseries\color{black}#1\strut};
\end{tikzpicture}};
\end{tikzpicture}
\fi\fi\par\vspace*{180\p@}}}

%-------------------------------------------
\def\@makeschapterhead#1{%
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.north west)
{\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north west,inner sep=0pt] at (0,0) {\ifusechapterimage\includegraphics[width=\paperwidth]{\thechapterimage}\fi};
\draw[anchor=west] (\Gm@lmargin,-7cm) node [line width=2pt,rounded corners=0pt,draw=basecolour,fill=white,fill opacity=0.9,inner sep=15pt]{\strut\makebox[22cm]{}};
\draw[anchor=west] (\Gm@lmargin+.3cm,-7cm) node {\huge\sffamily\bfseries\color{black}#1\strut};
\end{tikzpicture}};
\end{tikzpicture}
\par\vspace*{180\p@}}
\makeatother

%----------------------------------------------------------------------------------------
%   HYPERLINKS IN THE DOCUMENTS
%----------------------------------------------------------------------------------------
\usepackage{hyperref}
\hypersetup{hidelinks,colorlinks=false,breaklinks=true,urlcolor= basecolour,bookmarksopen=false,pdftitle={Title},pdfauthor={Author}}
\usepackage{bookmark}
\bookmarksetup{
open,
numbered,
addtohook={%
\ifnum\bookmarkget{level}=0 % chapter
\bookmarksetup{bold}%
\fi
\ifnum\bookmarkget{level}=-1 % part
\bookmarksetup{color=basecolour,bold}%
\fi}
}


%----------------------------------------------------------------------------------------
%   QUIZ
%----------------------------------------------------------------------------------------
%\alph*$\square$ 

% \newlist{questionlist}{enumerate}{2}
\usepackage{multicol}
\newlist{quizlist}{enumerate}{2}
\setlist[quizlist]{label=\textbf{$\square$ \alph*)},itemsep=4pt,topsep=4pt}
% \usepackage{pifont}
% \newcommand{\cmark}{\ding{51}}%
% \newcommand{\xmark}{\ding{55}}%
% \newcommand{\done}{\rlap{$\square$}{\raisebox{2pt}{\large\hspace{1pt}\cmark}}%
% \hspace{-2.5pt}}
% \newcommand{\wontfix}{\rlap{$\square$}{\large\hspace{1pt}\xmark}}

编辑:

上面的问题已经解决了,谢谢!但似乎还有另一个问题。我连续添加 2 张图片的命令运行正常,但可能写得也不太好,所以如果可能的话,请帮我修复它。我真的不知道如何在删除子图时使用浮点数。

\newcommand{\doubleimage}[6]{
\begin{figure}[ht]
\centering
\begin{subfigure}[t]{0.48\textwidth}
\fcolorbox{frameColor}{white}{\includegraphics[width=\textwidth]{#1}}%
\caption{#3}
\label{#5}
\end{subfigure}
\hspace{\fill}
% \qquad
\begin{subfigure}[t]{0.48\textwidth}
\fcolorbox{frameColor}{white}{\includegraphics[width=\textwidth]{#2}}%
\caption{#4}
\label{#6}
\end{subfigure}
\end{figure}
\FloatBarrier
}

输出看起来就像在图像中一样,并且保持如下所示。2 个图像左右对齐,中间有小间隙,2 个字幕不浮动在段落之间。

并排显示 2 张图片

我还修改了显示字幕的方式,希望它不会中断:

\renewcommand\thesubfigure{Rys. \thefigure\alph{subfigure}:}

答案1

您可以尝试不使用figure环境:

\newcommand{\image}[4][40mm]{
    \centering%
    \fcolorbox{frameColor}{white}{\includegraphics[width=\textwidth, height = #1, keepaspectratio]{#2}}
    \captionof{figure}{#3}%
    \label{#4}
}

相关内容