为什么图像会把文本拉下来?

为什么图像会把文本拉下来?

每当我添加图片时,文本都会被拉下来。我不希望这样,我希望文本保持正常,然后图像可以放在适合的位置,要么是当前页面,要么是下一页(如果太大)。

MWE 将是:

\documentclass{book}

\usepackage[utf8]{inputenc}
\usepackage[margin = 2cm]{geometry}
\usepackage{array}
\setlength{\arrayrulewidth}{1mm}
\setlength{\tabcolsep}{18pt}
\renewcommand{\arraystretch}{1.5}
\usepackage{color}
\newcommand{\compl}[1]{ \textcolor{darkblue}{\textbf{\hl{ #1 }}}}
\definecolor{seccol}{rgb}{0,0.8,0.3}

\usepackage{graphicx}

\begin{document}

    In a fully implemented Operating System, any global variables that need to be initialized before they are used, and any library initialization code needs to be called before these libraries cna be used. In our modest project, there are only a couple of libraries, but they need to be initialized nonetheless. Also, the  section must be cleared (i.e we must write a 0 to all addresses in the section). All of this is done in the  function.
    \\
    Although very humble in it's current state, if the project is extended so that more functionality is added, this is where we would call any library initialization code, in order to ensure that everything is setup before any function in a library gets called. 
    \\~\\
    The very first thing we want to do is clear the  section. Thanks to our, we have a label to indicate exactly where this section begins and another label to indicate exactly where it ends, the script also ensures that all  sections of all files get contiguously put together in the final kernel image, so we know that, once we clear this section, all variables that need to be initialized to 0 will contain their correct values. Since the addresses form a continuous block of memory, we can

        In a fully implemented Operating System, any global variables that need to be initialized before they are used, and any library initialization code needs to be called before these libraries cna be used. In our modest project, there are only a couple of libraries, but they need to be initialized nonetheless. Also, the  section must be cleared (i.e we must write a 0 to all addresses in the section). All of this is done in the function.
        \\
        Although very humble in it's current state, if the project is extended so that more functionality is added, this is where we would call any library initialization code, in order to ensure that everything is setup before any function in a library gets called. 
        \\~\\
        The very first thing we want to do is clear the  section. Thanks to our , we have a label to indicate exactly where this section begins and another label to indicate exactly where it ends, the script also ensures that all sections of all files get contiguously put together in the final kernel image, so we know that, once we clear this section, all variables that need to be initialized to 0 will contain their correct values. Since the addresses form a continuous block of memory, we can

                The very first thing we want to do is clear the  section. Thanks to our , we have a label to indicate exactly where this section begins and another label to indicate exactly where it ends, the script also ensures that all sections of all files get contiguously put together in the final kernel image, so we know that, once we clear this section, all variables that need to be initialized to 0 will contain their correct values. Since the addresses form a continuous block of memory, we can
\centering
\includegraphics{FramebufferDiagram.png}
\end{document}

[1]:https://i.stack.imgur.com/7lN韓國語.png

答案1

你需要将你的图片放入一个figure环境中以使其浮动:

\begin{figure}
\centering
\includegraphics{FramebufferDiagram.png}
\end{figure}

您可以添加可选参数来设置定位。h例如,此处(在源中出现的位置)、t页面顶部和/或b页面底部(\begin{figure}[ht]将其放在此处,或者如果不适合,则放在下一页的顶部)。

注意:您的文本仅占半页。由于您使用了该类,因此book文本仍将被拉伸,直到您添加更多文本。这是因为该类book试图使所有页面的高度相同。

编辑:

为了避免拉伸放入\raggedbottom序言中的页面,LaTeX 将不再尝试使所有页面具有相同的高度。

顺便说一句:既然你不想让图片浮动,我建议将\centering\includegraphics放在一个组中({...})。这样,图片后面的文本就不会再居中了。(我猜你不想要这样。)

答案2

评论太长:\raggedbottom无法解决使用\\~\\而不是空行 (= \par)在段落之间留空行是完全错误的。你只是插入了两个换行符 之内一个段落。即便如此,段落跳过也是不同的,并且假段落中没有段落缩进。

此外,您在 \centering最后一段的结尾前放置了一个空格,这样不仅图像居中,最后一段也居中。图像也是段落的一部分,就像一个巨大的字符,因此高度会略小一些,结尾会与“...memory, we can”相同。否则会转到下一页,但会留下大约 10 厘米的“空洞”。LaTeX 随后会在真正的段落之间使用橡胶间距,这些间距会拉伸以使文本垂直对齐。即使图像位于不同的段落中,也会发生这种情况。

如果希望段落之间有一些固定的空间,则应使用以下命令:

\setlength{\parskip}{\baselineskip}

请注意,这根本不需要,\raggedbottom因为现在段滑是固定长度,而不是橡胶长度。

尽管如此,通常最好保留一个可调整的长度(但页面的所有段落都相同),例如:

\setlength{\parskip}{.5em plus .1em minus .1em}      

parskip或者更简单:使用序言中的包。

在这种情况下,这显然不是一个好的解决方案,因为您迫使 Latex 在两种方法之间做出选择(让大约一半的页面空白,或者在段落之间留下较大的空白,甚至远远超出您的预期)。正如 Gustavo Mezzetti 所指出的那样,在这种情况下,解决方案是使用 、ht选项进行浮动p,因为这样图像就不再是正常段落的一部分了。

值得一提的是,浮动通常也是更好的选择,因为它可以在图形和上方和/或下方的文本之间留出适当的空间(并允许编号标题、图形列表、垂直居中单独的图像等)。

无浮动的 MWE:

姆韦

\documentclass{book}
\usepackage[margin=2cm]{geometry}
\setlength{\parskip}{\baselineskip}
\usepackage{graphicx}
\usepackage{kantlipsum} % allow \kant[n] for dummy paragraphs
\begin{document}
\kant[2]\par\kant[1]\par\kant[2]\par\kant[1]\par

\centering
\includegraphics[height=12cm]{example-image}
\end{document}

带浮点的 MWE:

姆韦

\documentclass{book}
\usepackage[margin=2cm]{geometry}
\setlength{\parskip}{.5em plus .1em minus .5em}
\usepackage{graphicx}
\usepackage{kantlipsum} % allow \kant[n] for dummy paragraphs
\begin{document}
\kant[2]\par\kant[1]\par\kant[2]\par\kant[1]
\begin{figure}[h]
\centering
\includegraphics[height=12cm]{example-image}
\end{figure}
\end{document}

注意:\par(= 空行)已隐含在\kant宏中,但我将其留在 MWE 中以注释段落以 结尾\par(当然,因为额外的 \par 会被忽略)。

相关内容