I often format path names with \texttt which can be very long. Usually Tex will not break this text. The line will just create a hbox overflow. It looks like this:
................
...C:\documents and settings
................
................
................
................
................
................
................
How do I get Tex to create a line break?
Best Answer
If you are using the default LaTeX fonts (or a small number of others), you can enable hyphenation within
\texttt
using thehyphenat
package:Note that this still won't do a great job of formatting arbitrary strings because it will be relying on the hyphenation patterns in use.
If your problem is about typesetting paths specifically, another option (arguably better) is to load the
url
package and use its\path{...}
command:This can have limitations with non-ASCII characters, however. If you get really stuck, you can force a line to end using
\newline
(aka\\
) or\linebreak
. These differ in important ways:\newline
will cause the paragraph to end the line abruptly at that point, whereas\linebreak
will still attempt to fill the line completely for justification purposes. This is illustrated in the following example: