3

I hope this question is not a trivial one, but I was not able to find any answer to that.

I found out that sometimes when I put an \hfill command in order to align some text to the right, there is a line break after the first word of the right-aligned text, even though there is surely enough space from the text on the left.

After playing with it a bit, it seems to me that it happens after there was a line break within a word in the paragraph.

I can't see any reason for that, but yet again I might not have a full understanding of how line breaking and \hfill work.

Here is a minimal example:

\documentclass{article}
\begin{document}

If there is a line break within a word as a result of some verymuchsuperlongword, 
then the text after hfill breaks: \hfill Some words.

If there isn't a line break within a word as a result of some very much super long word, 
then everything looks fine: \hfill  Some words.

\end{document}

And that's how it looks:

enter image description here

Does anyone have any idea what might be the problem and how I can avoid it?

Moysh
  • 43
  • 1
    Welcome to TeX.SX! Indeed, the issue is due to the hyphen, because TeX will prefer a paragraph where the last but one line is not hyphenated. The \hfill makes it possible. Is the \hfill used for setting an author attribution? If you type \hfill Some~words. then there will be no additional line. However, the \hfill could fail to push the words at the end of the line, if it comes too near the right margin. – egreg Aug 27 '14 at 21:05
  • See http://tex.stackexchange.com/questions/91548/bump-right-aligned-text-to-next-line-iff-no-room – egreg Aug 27 '14 at 21:10
  • Thanks egreg! In my case using \hfill some~words wouldn't help since what I actually want to put there is a citation. What does work is the solution in the link you've posted, that is: adding \linepenalty100\exhyphenpenalty0 before. Thanks a lot again! – Moysh Aug 27 '14 at 21:27
  • Can we close this as a duplicate, then? Don't worry about this, it's common for newcomers who can't be at ease with the search functions of the site. I could remember the question because I added a clue to my answer. – egreg Aug 27 '14 at 21:34
  • Sure. I guess this isn't something I can do, being a newcomer. – Moysh Aug 27 '14 at 21:56

0 Answers0