I was checking the notes from my physics class and I noticed that section 1.2 and the subsection 1.2.1 aren't aligned correctly... What's the issue?
\documentclass{book}
\usepackage[a4paper,top=1.5in,bottom=2in]{geometry}
\usepackage{
amsmath,
amssymb,
amsthm,
booktabs,
color,
mathrsfs,
psfrag,
pgfplots,
physics,
tikz}
\usetikzlibrary{quotes,angles}
\usepgfplotslibrary{colorbrewer}
\pgfplotsset{width=8cm,compat=1.9}
\title{Appunti di Fisica 2}
\author{Abcd}
\definecolor{mygray}{RGB}{240,240,240}
\begin{document}
\maketitle
\chapter{Elettromagnetismo}
\section{La forza di Coulomb}
\noindent La forza di Coulomb è la forza che attrae o respinge due cariche elettriche puntiformi
$$ \vb{F_1}=\frac{Q_1 Q_2}{4 \pi \epsilon_0} \cdot \frac{\vb{r_1}-\vb{r_2}}{\left| \vb{r_1}-\vb{r_2}\right|^{3}} $$
\begin{enumerate}
\item La forza esercitata dalla seconda carica è $\vb{F_2} = -\vb{F_1}$
\item $\epsilon_0$ la costante dielettrica del vuoto e vale $8.85 \cdot 10^{-12}, Fm^{-1}$
\item Il protone ha carica pari a $1.6 \cdot 10^{-19}, C$
\item L'elettrone ha carica pari a $-1.6 \cdot 10^{-19}, C$
\end{enumerate}
\noindent Ci sono tre tipi di densità di carica elettrica:
\begin{itemize}
\item \textbf{Lineare:}
E' la quantità di carica per unità di lunghezza.
$$ \lambda(\vb{r'})=\frac{\mathrm{d}q'}{\mathrm{d}l'} $$
\item \textbf{Superficiale:}
E' la quantità di carica per unità di superficie.
$$ \sigma(\vb{r'})=\frac{\mathrm{d}q'}{\mathrm{d}S'} $$
\item \textbf{Volumetrica:}
E' la quantità di carica per unità di volume.
$$ \rho(\vb{r'})=\frac{\mathrm{d}q'}{\mathrm{d}V'} $$
\end{itemize}
\newpage
\quad
\section{Il campo elettrico}
$$ \vb{E}(\vb{r})=\frac{1}{4 \pi \epsilon_0} \sum_{i=1}^{N} Q_i \frac{\vb{r}-\vb{r_i}}{\left| \vb{r}-\vb{r_i} \right|^{3}} $$
\noindent Quando le cariche non sono finite (e quindi N tende all'infinito):
$$ \vb{E}(\vb{r})=\frac{1}{4 \pi \epsilon_0} \int_{}^{}\frac{\vb{r}-\vb{r'}}{\left|\vb{r}-\vb{r'} \right|^{3}},\mathrm{d}q' $$
\subsection{Campo elettrico di un filo rettilineo uniformemente carico}
\begin{center} \begin{tikzpicture}
\filldraw[fill=mygray] (-10cm,-0.2cm) rectangle (4cm,0.2cm);
\draw[dashed] (-3cm,-1cm) -- (-3cm,4cm);
\filldraw[fill=orange] (-1cm,-0.2cm) rectangle (-0.5cm,0.2cm) node[above right=5pt]{$dx$};
\draw[dashed] (-0.75cm,0.2cm) -- (-3cm,4cm) node[midway, above right]{$r$};
\filldraw (-3cm,4cm) circle[radius=2pt] node[above right]{$P$};
\draw (-10cm,0.2cm) -- (4cm,0.2cm) node[left,above left]{$L$};
\draw (-3cm,-0.2cm) -- (-1.5cm,-0.2cm) node[midway,below=5pt]{$x$};
\draw[-{stealth[scale=2]}] (-3cm,4cm) -- (-3.9cm,6cm) node[above left]{$dE$};
\draw[-{stealth[scale=2]}] (-3cm,4cm) -- (-3cm,6cm) node[above right]{$dE_y$};
\draw (-3cm,0) coordinate (a)
(-3cm,4cm) coordinate (b)
(-0.75cm,0.2cm) coordinate (c)
pic["$\theta$",draw=orange,angle eccentricity=1.3,angle radius=1.25cm]{angle=a--b--c};
\end{tikzpicture} \end{center}
$$ E=E_y=\int_{C}^{}\frac{\mathrm{d}q \cos \theta}{4 \pi \epsilon_0 r^2} = \int_{-L/2}^{L/2}\frac{\lambda y \mathrm{d}x}{4 \pi \epsilon_0 (x^2+y^2)^{3/2}} = \frac{Q}{2 \pi \epsilon_0 y (L^2+4y^2)^{1/2}} $$
\noindent Se il filo è infinito:
$$ E=\lim_{L\to \infty} \frac{Q}{2 \pi \epsilon_0 y (L^2+4y^2)^{1/2}} = \frac{\lambda}{2 \pi \epsilon_0 y} $$
\subsection{Campo elettrico di un anello uniformemente carico}
\begin{center} \begin{tikzpicture}
\draw (0,0) coordinate (a)
(200pt,-50pt) coordinate (b)
(0,100pt) coordinate (c) node[above left]{dL}
pic["$\theta$", draw=orange, angle eccentricity=1.2, angle radius=2cm]
{angle=c--b--a};
\draw (0,0) ellipse [x radius=70pt, y radius=100pt];
\draw[thick] (0,0) -- (0,100pt) node[midway, left]{$R$};
\draw[thick, dashed] (0,0) -- (200pt,-50pt) node[midway, above=12pt, left]{$x$};
\draw[thick, dashed, red] (200pt,-50pt) -- (0,100pt) node[midway, above=5pt]{$r$};
\draw[-{stealth[scale=2]}] (200pt,-50pt) -- (300pt,-75pt) node[above right]{$\vec{dE_x}$};
\filldraw[thick] (200pt,-50pt) circle [radius=2pt] node[above right]{$P$};
\draw[-{stealth[scale=2]}] (200pt,-50pt) -- (270pt,-95pt) node[above right]{$dE$};
\end{tikzpicture} \end{center}
$$ E=E_x = \int_{C}^{} \frac{\mathrm{d}q \cos \theta}{4 \pi \epsilon_0} = \int_{0}^{2 \pi R} \frac{\lambda x}{4 \pi \epsilon_0 (x^2 + R^2)^{3/2}},\mathrm{d}L = \frac{Qx}{4 \pi \epsilon_0 (x^2+R^2)^{3/2}} $$
\[0.5cm]
\subsection{Campo elettrico di un disco uniformemente carico}
\noindent Il campo elettrico generato da un disco uniformemente carico è pari a quello generato da tutti gli anelli infinitesimali che lo compongono. Quindi
$$ \mathrm{d}E_x=\frac{x \mathrm{d}q}{4 \pi \epsilon_0 (x^2+r^2)^{3/2}} \to E_x=\int_{0}^{R} \frac{\sigma x}{4 \pi \epsilon_0 (x^2+r^2)^{3/2}}2 \pi R,\mathrm{d}r=\frac{\sigma}{2 \epsilon_0}\left[1-\frac{x}{(x^2+R^2)^{1/2}}\right] $$
Dove $r$ e $\mathrm{d}r$ sono rispettivamente il raggio e lo spessore di ogni anello infinitesimale. Se il disco è infinito:
$$ E=\lim_{R\to \infty} \frac{\sigma}{2 \epsilon_0} \left[1-\frac{x}{(x^2+R^2)^{1/2}}\right]=\frac{\sigma}{2 \epsilon_0} $$
\end{document}
Update: going on I found out it does that on every even page. Moreover, it isn't because of the center environment: I tried to remove it and they're still misaligned.
** It was the \documentclass{book}... I solved by changing it to \documentclass{report}.


\subsectioninbookis run-in, so the\centerfollowing the heading will ultimately affect the heading as well. Add something "harmless" (like$ $) following the heading and then a blank line to get out of horizontal mode. Unrelated: it's recommended to use\[ ... \]instead of$$with LaTeX. Finally, instead of using\\[<dimen>]after a display, enter a blank line, then\vspace{<dimen>}. The double backslash there will probably result in a confusing error message. – barbara beeton Dec 28 '22 at 15:49$ $ \\and a blank line of code after both\section{1.2}and\subsection{1.2.1}but they aren't aligned yet. Did I do something wrong? – David039 Dec 28 '22 at 16:02\\to end a paragraph; a blank line is enough. (See Best choice between using\\or leaving space after each paragraph to end the paragraph.) I'll try to test this when I'm able; without seeing the output, I can't picture the actual alignment. – barbara beeton Dec 28 '22 at 16:10\documentclass{book}. I changed it to\documentclass{report}and everything works fine. Sorry for wasting your time. – David039 Dec 29 '22 at 10:56