Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

When I use \hfill and in the previous line the last word is hyphenated, the \hfill doesn't work the same way as usual:

\documentclass[a4paper, 12pt]{book}
\begin{document}

Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but phonetic spellings are exceptions   \hfill go to library

AA Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but phonetic spellings  \hfill go to library

\end{document}

What should I write to get \hfill work like the first \hfill in the example?

share|improve this question
2  
Welcome to TeX.SX! Your problem has nothing to do with hyphenation. Is tex.stackexchange.com/questions/91548/… helping? –  egreg Dec 29 '13 at 17:34
    
alternatively to @egreg's link, you can try to reduce the occurrences of hyphenation by using the microtype package. In your mwe it works. –  ArTourter Dec 29 '13 at 17:42
    
Thank you both for your answers. I write mostly in greek, so I use the babel package and the microtype package does't reduce the occurrences of hyphenation, I don't know why. The link you gave me is not helping with hypernation. I found today this tex.stackexchange.com/questions/9325/… and @Jørgen Tesman describes the same problem with hypernation in his answer. –  Bozelou M. Dec 30 '13 at 18:47

2 Answers 2

The first solution is a modification of my solution to Bump right-aligned text to next line iff no room

I show also David's solution, in order to see where it can fail.

\documentclass[a4paper, 12pt,draft]{book} % draft for showing the overfull boxes

\newcommand*{\gotoend}[1]{%
  \unskip
  {\nobreak\hfill\penalty50\ \null\nobreak
   \hfill\mbox{#1}%
   \parfillskip=0pt \finalhyphendemerits=0 \par}
}

%% David's version
\newcommand*{\Dgotoend}[1]{\unskip\hspace*{\fill}\mbox{ #1}}


\begin{document}

Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but phonetic spellings are exceptions \gotoend{go to library}

AA Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but phonetic spellings \gotoend{go to library}

AA Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but AA phonetic spellings are just bigger 
exceptions \gotoend{go to library}

David's version:

Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but phonetic spellings are exceptions \Dgotoend{go to library}

AA Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but phonetic spellings \Dgotoend{go to library}

AA Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but AA phonetic spellings are just bigger exceptions \Dgotoend{go to library}

\end{document}

enter image description here

share|improve this answer
    
I'll give you a vote but I updated my solution a bit:-) –  David Carlisle May 29 at 22:31
    
I prefer the “Bourbaki” solution by Knuth. ;-) –  egreg May 29 at 22:33
    
This works!!! Thank you!!! –  Bozelou M. Jun 4 at 20:51

The behaviour isn't really related to hypphenation, but I think you just want to avoid the final phrase breaking over a line so:

enter image description here

\documentclass[a4paper, 12pt]{book}
\begin{document}

Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but phonetic spellings are exceptions\hspace*{\fill}\mbox{ go to library}

AA Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but phonetic spellings\hspace*{\fill}\mbox{ go to library}

\end{document}

You could make a macro out of this (and address egreg's point) by

\documentclass[a4paper, 12pt,draft]{book} % draft for showing the overfull boxes


%% David's version
\newcommand*{\Dgotoend}[1]{\unskip\hfill\penalty9999\hspace*{\fill}\mbox{ #1}}


\begin{document}


David's version:

Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but phonetic spellings are exceptions \Dgotoend{go to library}

AA Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but phonetic spellings \Dgotoend{go to library}

AA Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but AA phonetic spellings are just bigger exceptions \Dgotoend{go to library}

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.