2

My document sometimes has lines which slightly overflow into the margin, such as in the below example. I was wondering what different methods could resolve this issue, such as changing spacing between words, or forcing the last word to a new line. My text is justified, and I am suppressing hyphenation. If a general document-wide solution exists that I could just add to my preamble, that would be awesome, but various ad hoc solutions that resolve a single occurrence of the problem only would be quite fine too.

enter image description here

My clunky attempt at an MWE is below. It may be more superfluous than necessary, but it reproduces the problem.

\documentclass[a4paper,12pt]{book}
\usepackage{times}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}

\usepackage{geometry}
\geometry{bindingoffset=5mm}
\geometry{margin=2.54cm}

\hyphenpenalty=100000
%\pretolerance=10000
\tolerance=2000 
\emergencystretch=10pt

\begin{document}

\mainmatter
\chapter{Test}
\section{Aaaaaaaaaaaaaa bbbbb ccc ddddddd eeeeeee fffffffffffff}
\lipsum[1]

\end{document}
  • If you have lots of words like that, then you are going to have issues because TeX cannot hyphenate them. Assuming your actual document has real words in a real language, things are different. However, if you have prohibited hyphenation generally, then you will have issues because you've greatly reduced TeX's options. It can't find nice line breaks if you don't let it. Obviously, the issues will be greater in some languages than others since some languages are especially fond of long, compound words. But even if yours is not among them, long words are problematic if they cannot be hyphenated. – cfr Jan 5 '16 at 4:05
  • 1
    Using 12pt will make the problem worse, although reduced margins will help. Loading microtype can help in some cases, but it is likely a drop in the ocean if you've banned hyphenation. Why are you suppressing hyphenation? – cfr Jan 5 '16 at 4:07
  • times is obsolete, by the way, and ought no longer be used. – cfr Jan 5 '16 at 4:09
  • I suppressed hyphenation because it was making the document less readable. 99% of the time the resulting adjustments Latex makes to spacing are subtle and things still look fine despite hyphenation being forbidden, even with long words. microtype is not an option for this document due to some unrelated display issues. Neither is changing the font size. I've now replaced the times package with mathptmx. Is this more suitable? – Ulysses Jan 5 '16 at 6:46
  • Yes, mathptmx is a good alternative. In fact, it is the suggestion on CTAN's notes for times. (I just checked.) I don't find LaTeX hyphenates all that much in general, so I don't find it makes things less readable. Poor justification (e.g. large gaps between words) also makes text less readable, so readability is not necessarily enhanced by fewer hyphenated words. I wouldn't want hyphenation in section headings, though. I'd either set those ragged right or reword headings which proved problematic. \sloppy is a last resort, but I can only recall using this to accommodate e.g. a url. – cfr Jan 5 '16 at 17:26
1

To fix the issue of words in sectioning headers protruding into the right-hand margins, you could add the following two instructions to the preamble:

\usepackage{sectsty}
\allsectionsfont{\raggedright}

In general, if you absolutely do not want to permit hyphenation in the document, you could (a) issue the instruction \sloppy after \begin{document} (and be prepared to get some sloppy-looking paragraphs!) or (b) typeset the entire document ragged-right rather than fully justified.

  • I would like to keep headings as justified. Is there perhaps a Latex equivalent of the new line you get in MS Word with shift + enter? – Ulysses Jan 5 '16 at 8:29
  • @Ulysses - Just set \allsectionsfont{\sloppy}, then (and be prepared for some awfully sloppy looking sectioning headers). I'm afraid I don't "do" MS Word -- and thus don't even know what "shift + enter" does. – Mico Jan 5 '16 at 8:37
  • Is it possible to apply \sloppy to just the heading I'm having an issue with? It appears to have resolved the issue, but I'm not keen on going through and checking every single heading to see how they've changed, especially since I know they were fine to begin with. – Ulysses Jan 5 '16 at 11:05
  • Regarding MS Word: pressing enter gets you a new line/paragraph, while pressing shift + enter gives a new line, while making the previous line justified instead of left aligned (assuming body text is justified). – Ulysses Jan 5 '16 at 11:11
  • @Ulysses - Sounds like MS Word's shift+enter act exactly as \allsectionsfont{\sloppy} would: if one or more words don't fit on a line, they're pushed to the next line and the contents of the (underfull) line are spread out to create a justified look. If you insert the instruction \allsectionsfont{\sloppy} in the preamble, it'll apply to all sectioning instructions; isn't that what you would want? – Mico Jan 5 '16 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.