25

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.

enter image description here

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

1
  • 3
    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, 2011 at 20:04

5 Answers 5

16

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.

4
  • As I mentioned in a comment in Herbert's answer, the correct hyphenation is "meth\-od". Nov 13, 2011 at 23:13
  • @Gonzalo: Thanks - I've corrected it in my answer.
    – Werner
    Nov 13, 2011 at 23:28
  • 2
    \discretionary{meth-}{od}{method} seems quite overkill. :) meth\-od is the right way.
    – egreg
    Nov 13, 2011 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, 2011 at 23:23
14

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.

2
  • 1
    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…). Apr 23, 2012 at 4:00
  • microtype did the trick. Thank you a lot
    – davcha
    Dec 26, 2020 at 23:05
7

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.

6

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

More information in this answer.

2
  • 1
    This is the only solution that worked for me. I can not believe the default LaTeX settings allow the text to cross the margins... Jun 16, 2020 at 22:33
  • For me it seems to require \tolerance=99999 Dec 25, 2020 at 14:06
4

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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .