0

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

  • Welcome to tex.sx. Not tested: I believe \subsection in book is run-in, so the \center following 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
  • @barbarabeeton Thank you for all the useful notes about the notation. I'll keep them in mind. However, it still doesn't seem to work. I added $ $ \\ 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
  • You don't want that \\ 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
  • @barbarabeeton That's understandable. – David039 Dec 28 '22 at 16:32
  • Okay, I'm testing. I get an error that I can't get past: ! Missing \endcsname inserted. \theta l.71 ...ngle eccentricity=1.3,angle radius=1.25cm] {angle=a--b--c}; I tried setting this `tikzpicture` by itself, and got the same error, so there's some problem there that I can't figure out. Removing the `tikzpicture`s and replacing them with `\begin{center}dummy text \end{center}` resulted in aligned headings. So I conclude the problem is in the `tikz` code, which I'm not successfully debugging. – barbara beeton Dec 28 '22 at 22:06
  • @barbarabeeton Thanks a lot. You've been extremely helpful. – David039 Dec 28 '22 at 22:26
  • @barbarabeeton It was never the tikzpicture, It was the \documentclass{book}. I changed it to \documentclass{report} and everything works fine. Sorry for wasting your time. – David039 Dec 29 '22 at 10:56

1 Answers1

0

They are perfectly aligned against the left margin.

The class book uses twoside as default option, so the left and right margins are different and positioned symmetrically on even and odd pages.

You can make the margins equal to each other by using the oneside option.

Standard output

enter image description here

With oneside

enter image description here

Improvements

Your code needs several improvements. You should use \lvert and \rvert, not \left| and \right|. Also, the subscripts should go outside: look at the difference between \vb{F_1} and \vb{F}_1.

Never ever use $$ in LaTeX. And \noindent is rarely (if ever) used in a document.

Do you really need psfrag? If you don't know what a package is for, omit loading it.

Don't forget to announce LaTeX you're writing in Italian.

\documentclass{book}

\usepackage[a4paper,top=1.5in,bottom=2in]{geometry} \usepackage[T1]{fontenc} \usepackage[italian]{babel}

\usepackage{ amsmath, amssymb, amsthm, booktabs, color, mathrsfs, % psfrag, % <--- really? 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} 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}{\lvert \vb{r}_1-\vb{r}_2\rvert^{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} Ci sono tre tipi di densità di carica elettrica: \begin{itemize} \item \textbf{Lineare:} È la quantità di carica per unità di lunghezza. [ \lambda(\vb{r}')=\frac{\mathrm{d}q'}{\mathrm{d}l'} ] \item \textbf{Superficiale:} È la quantità di carica per unità di superficie. [ \sigma(\vb{r}')=\frac{\mathrm{d}q'}{\mathrm{d}S'} ] \item \textbf{Volumetrica:} È la quantità di carica per unità di volume. [ \rho(\vb{r}')=\frac{\mathrm{d}q'}{\mathrm{d}V'} ] \end{itemize}

\clearpage

\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}}{\lvert \vb{r}-\vb{r_i} \rvert^{3}} ] 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}'}{\lvert\vb{r}-\vb{r}' \rvert^{3}},\mathrm{d}q' ]

\subsection{Campo elettrico di un filo rettilineo uniformemente carico}

\begin{gather} \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} \ 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}} \end{gather} 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{gather} \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} \ 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}} \end{gather}

\subsection{Campo elettrico di un disco uniformemente carico}

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}

Check the differences.

egreg
  • 1,121,712
  • Thanks for all the advice. I changed my snippet for display math to use /[ /] already. Now I'll fix the other issues. – David039 Dec 29 '22 at 14:02