This is not exactly a problem I'm having, is more about how it works because I don't understand why LaTeX is behaving like this.
I have the following code:
\section{Ejercicios}
\newpage
\subsection{Creación guión del shell para obtener UID y GID de un usuario dado}
\begin{normalsize}
El lenguaje de programación que usaremos será bash, que a su vez es la aplicación de consola. Para este caso necesitaremos instrucciones simples como imprimir por pantalla o pedir una entrada al usuario.
\end{normalsize}
\subsection{Creación guión del shell para obtener logins de todos los usuarios dado un GID}
The output from the previous example is the following:

And the next section starts in the next page, which is what I don't understand.
If I put a shorter text, like in the next example, the next section starts right behind the previous one.

Is there any specific reason why this happens? Or am I doing something wrong? Thanks in advance
\@afterheadingis fighting\newpage. First, starting a section at the bottom of a page is not pretty. Second, put an invisible line (\nullor\rule{\linewidth}{0pt})) between the two. – John Kormylo Feb 11 '24 at 19:55