[Tex/LaTex] Dealing with overhanging text

line-breaking

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}
\setCJKmainfont{Adobe Song Std}
\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}
\setCJKmainfont{Adobe Song Std L}
\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.

Best Answer

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
Related Question