Cuando uso \hfill
y en la línea anterior la última palabra está dividida con guiones, \hfill
no funciona de la misma manera que de costumbre:
\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}
¿Qué debo escribir para conseguir \hfill
un trabajo como el primero \hfill
del ejemplo?
Respuesta1
La primera solución es una modificación de mi solución paraPasar el texto alineado a la derecha a la siguiente línea si no hay espacio
Muestro también la solución de David, para ver dónde puede fallar.
\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}
Respuesta2
El comportamiento no está realmente relacionado con la separación de palabras, pero creo que solo quieres evitar que la frase final se rompa en una línea, así que:
\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}
Podrías hacer una macro a partir de esto (y abordar el punto de egreg) haciendo
\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}