Problem mit \hfill und Silbentrennung

Problem mit \hfill und Silbentrennung

Wenn ich \hfillund in der vorherigen Zeile das letzte Wort mit Bindestrich verwende, \hfillfunktioniert das nicht so wie üblich:

\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}

Was muss ich schreiben, damit es \hfillwie das erste \hfillim Beispiel funktioniert?

Antwort1

Die erste Lösung ist eine Modifikation meiner Lösung fürRechtsbündigen Text in die nächste Zeile verschieben, wenn kein Platz vorhanden ist

Ich zeige auch Davids Lösung, um zu sehen, wo sie scheitern kann.

\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}

Bildbeschreibung hier eingeben

Antwort2

Das Verhalten hängt nicht wirklich mit der Silbentrennung zusammen, aber ich glaube, Sie möchten einfach vermeiden, dass die letzte Phrase über eine Zeile hinaus umbrochen wird, also:

Bildbeschreibung hier eingeben

\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}

Sie könnten daraus ein Makro machen (und auf egregs Punkt eingehen), indem Sie

\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}

Bildbeschreibung hier eingeben

verwandte Informationen