I'm writing up a long paper, in which in prose I have various equations. However, I do not want a line break to occur within the equation - I want the equation to stick together. I want to do this without displaying the equation, though. Is there a way to do this?
3 Answers
Anything you enclose within an \hbox or the equivalent LaTeX \mbox will not break. However overflowing into the margins is not a good idea. In the minimal below you can see the effect by using the geometry package to show a border around the normal text area.
\documentclass{octavo}
\usepackage[showframe=true]{geometry}
\begin{document}
\mbox{This is an extremely long line. This is extremely long. $a^2+c^2=42$ }
\end{document}
For long equations rather use the breqn package to break them at an appropriate point.
- 117,160
-
+1: I like the idea of using the geometry package to visualize the size of boxes. – Tatjana Heuser Mar 21 '12 at 09:26
-
@TatjanaHeuser -- Thanks there are also the
layoutsandlayoutpackages, you should give them a try. – yannisl Mar 21 '12 at 09:29
I use a solution to this problem that cannot be used always. Once I finish my work, I go thru the "almost-final" version of the whole paper and when an inappropriate break appears (inside equation, stupidly-broken name/date/... that does not look good in my opinion), I rephrase the text so that this piece appears in the middle of the line. Actually, you have to do the very same thing with overfull \hboxes anyways, but they are at least listed in the log.
Of course this needs you to be the author (of to have the author's permission to do small modifications) and it might be against the idea of TeX/LaTeX in someone's opinion (the idea is that you shouldn't have to do such things manually).
Edit / Added:
You can decide to enclose your math into \mbox{...} to disallow like breaking, as Yiannis Lazarides says in his answer. In this case the inline math will often go out of the line. You can visualize these overfull boxes by adding [draft] parameter to your \documentclass (works for most standard classes).
- 51,322
-
+1 This is the best solution. That is what I do as well. I have an
overfullrule1ptnormally during drafts and helps me visualize as I go along. Between various edits they tend to disappear. – yannisl Mar 21 '12 at 10:41 -
I could mention the
draftoption that visualizes overfull\hbox, I'm adding that. – yo' Mar 21 '12 at 10:50 -
@tohecz -- if you've read the texbook, you'd know that this is exactly what don knuth recommends (or at least practices himself). so it's not "against the idea of tex". – barbara beeton Mar 21 '12 at 13:25
-
@barbarabeeton Thanks for details, I changed "is completely" to "might be" ;) – yo' Mar 21 '12 at 13:26
If you use ~ instead of spaces the whole expression will stay together!
- 41
-
1
~is usually used in text mode to get an unbreakable space. Hyphenation of the words is still possible. – Heiko Oberdiek May 20 '16 at 19:58 -
\mbox) will produce overfull boxes (the equation will overflow the margin), which isn't desirable; you could try rephrasing the lines containing the equation so that a line break won't occur inside the equation. – Gonzalo Medina Mar 21 '12 at 02:39\linebreak[4]– Vivi Mar 21 '12 at 07:02\[ ... \]will accomplish that. this is usually better than forcing a line break and stretching out the preceding text, or leaving a short line. – barbara beeton Mar 21 '12 at 13:23