Por que as imagens puxam o texto para baixo?

Por que as imagens puxam o texto para baixo?

Sempre que incluo uma imagem, o texto é puxado para baixo. Não quero isso, quero que o texto fique normal e depois a imagem fique onde couber, seja na página atual ou na próxima se for muito grande.

O MWE seria:

\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/7lNPf.png

Responder1

Você precisa colocar sua foto em um figureambiente para fazê-la flutuar:

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

Você pode adicionar um argumento opcional para configurar o posicionamento. hpara aqui (onde aparece na fonte), tpara no topo de uma página e/ou bpara no final de uma página ( \begin{figure}[ht]para colocar aqui ou, se não couber, no topo da próxima página) .

Nota: seu texto ocupa apenas meia página. E como você está usando a bookclasse, ela ainda ficará esticada até você adicionar mais texto. Isso ocorre porque a bookclasse tenta fazer com que todas as páginas tenham a mesma altura.

Editar:

Para evitar esticar a página colocada \raggedbottomno preâmbulo. O LaTeX não tentará mais deixar todas as páginas com a mesma altura.

A propósito: como você não quer que a imagem flutue, recomendo colocar \centeringe \includegraphicsem um grupo ( {...}). Dessa forma o texto após a imagem não ficará mais centralizado. (Acho que você não quer isso.)

Responder2

Muito tempo para um comentário: \raggedbottomnão resolva que o uso \\~\\de em vez de umlinha em branco (= \par)deixar uma linha em branco entre os parágrafos é completamente errado. Você está inserindo apenas duas quebras de linha dentro deum parágrafo. Mesmo assim, os saltos de parágrafo são diferentes e não há recuo de parágrafo nos parágrafos falsos.

Além disso, você colocou um \centeringantes de finalizar o último parágrafo, para que não só a imagem fique centralizada, mas também o último parágrafo. A imagem também faz parte do parágrafo, e está agindo como um personagem enorme, então com um pouco menos de altura terminará na mesma linha que "...memória, podemos". Caso contrário passe para a próxima página, mas deixando um “buraco” de cerca de 10 cm. O LaTeX então usa espaçamento de borracha entre parágrafos verdadeiros que se estendem para tornar o texto justificado verticalmente. Isso acontecerá mesmo que a imagem esteja em um parágrafo diferente.

Se você quiser algum espaço fixo entre os parágrafos, você deve usar um comando como:

\setlength{\parskip}{\baselineskip}

Observe que isso não é necessário \raggedbottomporque agora o deslocamento do parágrafo tem um comprimento fixo, não um comprimento de borracha.

No entanto, normalmente é muito melhor deixar um comprimento adaptável (mas igual em todos os parágrafos da página) como:

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

ou mais simples: use o pacote parskipno preâmbulo.

Neste caso esta aparentemente não é uma boa solução porque obriga o Latex a decidir entre um mal e outro (deixou cerca de metade da página vazia, ou deixou um grande espaço entre os parágrafos, mesmo longe do desejado). A solução neste caso, como bem apontou Gustavo Mezzetti, um float com h, tou popções porque assim a imagem não faz mais parte de um parágrafo normal.

Vale ressaltar que um float também costuma ser preferível porque tome cuidado para deixar um espaço decente entre a figura e o texto acima e/ou abaixo (e permitir legendas numeradas, lista de figuras, centralizar imagens verticalmente sozinhas, etc.)

MWE sem flutuação:

eu

\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 com flutuador:

eu

\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}

Nota: \par(= linha em branco) já está implícito nas \kantmacros, mas deixo nos MWEs observar que os parágrafos terminam com \par(e porque \par extras são ignorados, é claro).

informação relacionada