# Why default behavior of section title is to overflow

The question I am asking here is not "how to fix" but rather "why is this the default behavior". For many things, I find that understanding why latex does what it does leads to me being able to write cleaner, and this is something I have never understood.

Here is a MWE:

\documentclass[12pt]{article}
\begin{document}
\section{Algebraic Geometry - Localization and Germs of Functions}
\end{document}


Compiled, it gives me an overfull warning and indeed, "Germs" goes over the right margin by ~20pt. Of course, this could have easily been avoided by moving Germs down to the next line where "of Functions" is located. For text in various other locations like a paragraph or a quote box, the overfull is always avoided. Why not for a section title? Is it considered better to overflow rather than not get very close to the right margin?

Perhaps there is no reason, and it "just is". I suppose I can accept that too.

-

The default behaviour isn't (directly) to overflow, but is to be justified, however with large heading fonts there are rather few inter-word spaces so justifying is rather difficult especially as there are high penalties for hyphenating a two-line paragraph (and you probably don't want a hyphenated section heading).

As usual with TeX's paragraph line breaker, it will go over-full and warn rather than stretch inter-word space beyond the constraints specified.

If you expect to have long headings, they should probably be set raggedright:

\documentclass[12pt]{article}
\begin{document}
\section{Algebraic Geometry -- Localization and Germs of Functions}

\makeatletter
\renewcommand\section{\@startsection {section}{1}{\z@}%
{-3.5ex \@plus -1ex \@minus -.2ex}%
{2.3ex \@plus.2ex}%
{\raggedright
\normalfont\Large\bfseries}}
\makeatother

\section{Algebraic Geometry -- Localization and Germs of Functions}

\end{document}

-
By "is to be justified", do you mean that the text should end precisely at the start of the right margin? – RghtHndSd Feb 25 at 19:51
@RghtHndSd yes, just like normal paragraph text. If you set that large font just in the text body you would see the same issues, the section head code does not do anything special about linebreaking, it is just concerned with setting the font and setting any vertical spaces. – David Carlisle Feb 25 at 20:10
Thanks. This definitely answers my question. I can understand such alignment for body text, it seems odd to me that it is important for section headers. – RghtHndSd Feb 25 at 20:18
@RghtHndSd without wanting to name the guilty one suspects that it is that way as that is the default paragraph setting and it wasn't thought about rather than it being a conscious decision. It is virtually impossible to change the default layout of the standard styles after 30+ years of use as it would change too many documents, so it is what it is. – David Carlisle Feb 25 at 20:20

David has taught you why it happens and suggested a remedy. You can take a shorter route, which basically amounts to the same, but avoids plunging into the details:

\documentclass[12pt]{article}

\usepackage{sectsty}

\allsectionsfont{\raggedright}

\begin{document}

\section{Algebraic Geometry - Localization and Germs of Functions}

\end{document}


-
This is not the question I was asking, but I suppose it could help someone else. Thanks for the response. – RghtHndSd Feb 26 at 0:11