# Dealing with overhanging text

I have a document with many long, unbreakable words. On A5, there are about 8 words per line. This creates a problem as on many lines, some words trail off the edge and well into the margins. I have found some words for which very far into the margins, nearly touching the edge of the page. On some pages, the problem is so frequent, that the right margin is not even visible.

What options do I have for solving this?

Update:

Here is a simplified sample of my code, so you can see what is happening:

\documentclass[crown,twoside]{octavo}
\pdfpagewidth=127mm
\pdfpageheight=191mm
\usepackage{xeCJK}
\usepackage{fontspec}
\usepackage{stackrel}
\setmainfont{Gentium Plus}
\newcommand{\stacked}[2]{%
$\stackrel{\textrm{#1}}{\textrm{#2}}$%
}
\begin{document}
This text should show you where the proper margins are, but as you can see, the text below is goes too far over the edge, which isn't too pleasant.
\stacked{床}{chuáng}\hskip0pt\stacked{前}{qián}\hskip0pt\stacked{明}{míng}\hskip0pt\stacked{月光}{yuè​guāng}，
\stacked{疑}{yí}\hskip0pt\stacked{是}{shì}\hskip0pt\stacked{地上}{dì​shang}\hskip0pt\stacked{霜}{shuāng}。
\stacked{举}{jǔ}\hskip0pt\stacked{头}{tóu}\hskip0pt\stacked{望}{wàng}\hskip0pt\stacked{明月}{míng​yuè}，
\stacked{低头}{dī​tóu}\hskip0pt\stacked{思}{sī}\hskip0pt\stacked{故乡}{gù​xiāng}。
\end{document}


This compiles with xelatex.

Update:

I found, my example (above) used too many short words, so when others compile it, it did not show the overhang very much. Here, I've modified the code a bit to simulate the results of having longer words. You should see that some words overhang completely off the page.

\documentclass[crown,twoside]{octavo}
\pdfpagewidth=127mm
\pdfpageheight=191mm
\usepackage{xeCJK}
\usepackage{fontspec}
\usepackage{stackrel}
\setmainfont{Georgia}
\newcommand{\stacked}[2]{%
$\stackrel{\textrm{#1#1}}{\textrm{#2#2}}$%
}
\begin{document}
This text should show you where the proper margins are, but as you can see, the text below is goes too far over the edge, which isn't too pleasant. \par
\stacked{床}{chuáng}\hskip0pt\stacked{前}{qián}\hskip0pt\stacked{明}{míng}\hskip0pt\stacked{月光}{yuè​guāng}，
\stacked{疑}{yí}\hskip0pt\stacked{是}{shì}\hskip0pt\stacked{地上}{dì​shang}\hskip0pt\stacked{霜}{shuāng}。
\stacked{举}{jǔ}\hskip0pt\stacked{头}{tóu}\hskip0pt\stacked{望}{wàng}\hskip0pt\stacked{明月}{míng​yuè}，
\stacked{低头}{dī​tóu}\hskip0pt\stacked{思}{sī}\hskip0pt\stacked{故乡}{gù​xiāng}。

\end{document}


The \hskip0pt serves to allow line breaks, without making spaces and because hyphens are not suitable.

-
Please add a MWE. – Count Zero Nov 22 '11 at 12:37
You could use \sloppy, but try the microtype package as well. See tex.stackexchange.com/q/32202/4301 – Peter Grill Nov 22 '11 at 12:37
This is basically a duplicate of tex.stackexchange.com/questions/34721/… – Karl Ove Hufthammer Nov 22 '11 at 12:47

The “l2tabuen.pdf” lists examples how to influence the line breaking in TeX under section 1.8 “Should I use \sloppy?”. In the newer German version, the effect is more visible as the text actually exceeds the bounding box which is then fixed with \sloppy (which should not be used according to the document).

Why are the words unbreakable? You could add custom hyphenation rules for these words if they are just hyphenated wrongly.

-
The words are unbreakable because they are placed into stackrels. Is it possible to break a stackrel's text across 2 lines? – Village Nov 22 '11 at 13:02
I agree with Count Zero that you should provide a Minimal Working Example (MWE), because it might be more efficient to look for alternatives to stackrel. But this becomes clearer with an actual example at hand with which can be worked. – brian-ammon Nov 22 '11 at 13:57
The comment, "words are unbreakable because they are placed into stackrels," raises the obvious question, "Why"?! Please provide a minimum working example (MWE) of code that illustrates the problems you're experiencing. – Mico Nov 22 '11 at 18:26
I have updated my question to include an example which illustrates the problem. – Village Nov 23 '11 at 7:14
I have tried out your example. As I did not have your fonts available, I used “Helvetica” and “STSong”. The problem did not occur as drastic to me as you described it. I have found that removing the \hskip0pt between the \stackrels seems to help a little. – brian-ammon Nov 24 '11 at 19:31

It depends of course on the constraints you face, but generally speaking you can:

• help TeX with finding the right hyphenation points by providing \hyphenation{words} for the long words, perhaps you are using a language that TeX is not familiar with, see the UK TeX FAQ and this entry too
• rephrase the sentence,
• change the margins,
• change the page layout,
• change the font size,
• change the font to one that runs narrower,
• change the paper size
• tweak TeX's line breaking parameters see the UK TeX FAQ
-