# Why do hyphenated words cause margin violations (and how can I prevent it)?

Sometimes my text goes past the right margin when there is a hyphenated word involved in the sentence. For example, in the figure below, the line that contains "inter-member" extends further right than the lines in the rest of the text. I most often see this behavior when the hyphenated word is the last word on the line.

Why does this happen, and how can I prevent it?

-
This should not be isolated to sentences with hyphenated words in them. Here the word `method` causes the "violation", output in your `.log` file as "badness". Rewording your sentence would work. –  Werner Nov 13 '11 at 20:04

For completeness, from the TeX Book:

Roughly speaking, TeX breaks paragraphs into lines in the following way: Breakpoints are inserted between words or after hyphens so as to produce lines whose badnesses do not exceed the current `\tolerance`. If there's no way to insert such breakpoints, an overfull box is set. Otherwise the breakpoints are chosen so that the paragraph is mathematically optimal, i.e., best possible, in the sense that it has no more "demerits" that you could obtain by any other sequence of breakpoints. Demerits are based on the badnesses of individual lines and on the existence of such things as consecutive lines that and with hyphens, or tight lines that occur next to loose ones.

TeX issues breakpoints via hyphenation based on a number of passes of a paragraph (yes, an entire paragraph*; not just on a line-by-line or sentence-by-sentence basis).

So, in order to avoid poor line-breaking, you could

• reword some parts of your paragraph which could lead to better hyphenation;

• use discretionary hyphenation: `meth\-od` within the text, `\hyphenation{meth-od}` somewhere else or `\discretionary{meth-}{od}{method}`; or

• use `babel` for language-specific improved hyphenation.

* See Components of (La)TeX's memory usage for some discussion an examples of memory usage when it comes to paragraph construction and line-breaking.

-
As I mentioned in a comment in Herbert's answer, the correct hyphenation is "meth\-od". –  Gonzalo Medina Nov 13 '11 at 23:13
@Gonzalo: Thanks - I've corrected it in my answer. –  Werner Nov 13 '11 at 23:28
`\discretionary{meth-}{od}{method}` seems quite overkill. :) `meth\-od` is the right way. –  egreg Nov 13 '11 at 23:42
Now I'm wondering how this works when combined with microtype, when does it change character size, when does it hyphenate? Guess I could make a question or try and wade through the documentation. –  Canageek Nov 14 '11 at 23:23

This is actually a FAQ, (La)TeX makes overfull lines. The simplest and best solution, as @Canagreek mentioned, is to load the `microtype` package. This will greatly reduce the number of overfull lines, and generally make paragraphs look much better (uniform greyness and fewer hyphenated words).

If you still get overfull lines, and are willing to accept quite ugly paragraphs, you can add the command `\sloppy` command. This sets the `\tolerance` mentioned in @Marco’s answer to 9999 (the largest possible finite value), but also changes a few other parameters. The opposite of `\sloppy` is `\fussy` (and is the default).

Also make sure you load the correct hyphenation dictionaries for your text, e.g., `\usepackage[UKenglish]{babel}`. Otherwise, TeX may have trouble find hyphenation points for words, or use the wrong hyphenation points.

-
Thank you. This link to the FAQ has saved me from asking my own version of this question (because I can't rewrite the text of the book I'm laying out…). –  Austin Ziegler Apr 23 '12 at 4:00

Using the microtype package will will help this if you are on PDFTeX (and I've heard comments saying it is possible to get it to work with LuaTeX) by reducing the amount of hyphenation needed. I don't think it will fix the problem of irregular spacing, but it would make it occur less often ---I have a 5 page document I'm working on right now, and it doesn't have a single instance of hyphenation.

-

TeX doesn't find a suitable line break. TeXs spacing between the words is rather strict. You can control the behaviour with the `\tolerance` setting. For instance you can set

```\tolerance=5000
```

-

there is no hypen rule for method. Write into your preamble

``````\hyphenation{meth-od}
``````

or write it as `meth\-od`. But I am not really sure if it can be hyphenated in this way.

-
I think "meth\-od" is the right hyphenation. –  Gonzalo Medina Nov 13 '11 at 20:55
@GonzaloMedina Yes, the Merriam-Webster says "meth-od". –  egreg Nov 13 '11 at 21:25
ok, I'll changed it and will send a report to BB for the hyphenation exception list –  Herbert Nov 14 '11 at 8:03
Why the downvote? –  Werner Nov 14 '11 at 8:07