Tell me more ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm somewhat new to LaTeX and have been tasked with satisfying some strict formatting requirements for this LaTeX document using a custom class.

Currently, if there is a long chapter name (within a certain window around 1 line in length), it will show up on one line with the page number "pushed" outside the right margin. This isn't allowed, so how can I wrap these slightly-too-long chapter headings and avoid printing the page number outside the right margin?

I've already tried \setlength{\hfuzz}{0.0pt} which I read about here but it sounds like that only applies to TeX, not LaTeX. In any case, it didn't work.

EDIT: Here is an example that illustrates the problem. The class I'm using/writing is based on report, and report has exactly the same problem, viewable to all in the following document:

\documentclass{report}

\begin{document}

\tableofcontents

\chapter{xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx 1234567890}

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

\chapter{xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx 1234567890}

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

\chapter{xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx12345}

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

\end{document}

When generated (with pdflatex in my case), the table of contents looks like this:

heading omitted, table of contents shown

As you can see, the first title is short enough that it is on one line. The second is long enough that it is broken into two lines. The third, however, is somewhere in between and only pushes the page number (4) outside the margins. The first and second page numbers are correctly within the margins.

Given the strict margin requirements for these documents, I need the third title to break, probably with a hyphen, within the margin. I've seen this done, and in that case it broke right before where the page numbers are printed normall.

share|improve this question
2  
I tried to reproduce the problem, but failed. Could you please post a example (do including your documentclass). – Caramdir Oct 19 '10 at 21:51
1  
LaTeX is a set of TeX macros. \hfuzz is a TeX primitive so it absolutely applies to LaTeX. It's just irrelevant here. It controls the amount a box may be overfull before TeX reports it as such. – TH. Oct 20 '10 at 4:47
Thanks for that info, TH. – zuwiki Oct 22 '10 at 19:31
@Caramdir: I've added an example, but I didn't include the document class because it is based on report and doesn't change all that much. I really need to figure out what I need to change from the report documentclass, which has the same problem. – zuwiki Oct 22 '10 at 19:33
1  
A non-answer to your problem, but probably trying to have short concise titles for your chapters will help your readers to more easily grasp the contents of your document, as well as avoid this kind of issues. – Juan A. Navarro Nov 10 '10 at 17:29

4 Answers

up vote 6 down vote accepted

It seems like (La)TeX has problems hyphenating the word at the end of the line (like with xxxxx12345) and decided that breaking the line before the word would look worse. Maybe you need to load hypenation patterns for your language (via babel) or it is just some word with “special characters” (i.e. not in the a-z, A-Z range, like 1 or ü). In this case it is probably easiest to explicitly tell TeX where it is possible to break the word by marking the positions with \-. For example, the above word might be marked as xxx\-xx\-123\-45, which gives

example

share|improve this answer
It's all alphanumeric (and probably alphabet-only), and using babel didn't work. While it's not optimal, your \- solution is better than nothing and will work. If anyone has anything better (i.e. I don't have to ask grad students to do something like that manually), I'd love to hear it. Thanks Caramdir! – zuwiki Oct 22 '10 at 20:29
2  
If you want to wait for another answer you should wait with accepting, because many people ignore questions with accepted answers. – Caramdir Oct 22 '10 at 21:29

You may use the tocstyle package which is included in KOMA-Script to set the ToC entries raggedright (and thereby avoid problematic line breaks). Add the following to your preamble:

\usepackage{tocstyle}
\usetocstyle{standard}
\settocfeature{raggedhook}{\raggedright}

Note that the package has "alpha" status.

share|improve this answer
This is a great solution. Unfortunately, in my case it produces toc lines, that might have a page-break inbetween. As you said, alpha... – kongo09 Oct 20 '11 at 0:09

I was searching the internet and reading documentations for a solution for hours. This research also led me to this page, unfortunately without providing me a satisfactory answer.

So this is my solution:

\addtocontents{toc}{\protect\sloppy}
\tableofcontents
\addtocontents{lof}{\protect\sloppy}
\listoffigures
\addtocontents{lot}{\protect\sloppy}
\listoftables

I hope this is useful to anybody who is experiencing the same problem with Captions in ToC/LoF/LoT passing the margin and moving the page number.

share|improve this answer
This is great and works well – kongo09 Oct 20 '11 at 0:12
I am unable to use \addtocontents{toc}{\protect\sloppy} \tableofcontents I tried using \usepackage[breaklinks=true]{hyperref} and it worked.. :) but the chapter name which was long, is not clickable anymore.. I can click on other chapters and sections, but not on this one.. – Swati Jun 11 '12 at 6:14

(Polishes crystal ball) Let me guess: you are using the hyperref package and you are not using pdflatex. Try adding the linktocpage option to your \usepackage{hyperref} line. Failing that, better follow Caramdir's advice to post an example.

share|improve this answer
2  
I am using pdflatex, I am not using hyperref. I'll follow Caramdir's advice. Thanks though! – zuwiki Oct 22 '10 at 19:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.
http://tex.stackexchange.com/questions/4311/how-can-i-force-long-chapter-names-including-page-numbers-to-stay-in-the-margi
tex.stackexchange.com
crawl=CC-MAIN-2013-20
61579
application/http; msgtype=response
sha1:4R7LM75VKMTBWGIO43DCJAHYW6RUJI7Y
<urn:uuid:ed920226-e8ae-459c-bec8-78f496bb7643>
2013-05-19T18:02:07Z
198.252.206.16
sha1:7IFR4RCSVVZORM55VZX3WBEACVEDHJAW
<urn:uuid:1d17fc85-cccd-478b-b8f5-1c1d74a3d757>
http://tex.stackexchange.com/questions/4311/how-can-i-force-long-chapter-names-including-page-numbers-to-stay-in-the-margi
response
<urn:uuid:bd3e93f7-18fc-4348-b6d0-2a6380e6702a>
robots: classic
hostname: ip-10-60-113-184.ec2.internal
software: Nutch 1.6 (CC)/CC WarcExport 1.0
isPartOf: CC-MAIN-2013-20
operator: CommonCrawl Admin
description: Wide crawl of the web with URLs provided by Blekko for Spring 2013
publisher: CommonCrawl
format: WARC File Format 1.0
conformsTo: http://bibnum.bnf.fr/WARC/WARC_ISO_28500_version1_latestdraft.pdf