\hfill 和连字符的问题

\hfill 和连字符的问题

当我\hfill在上一行中使用并且最后一个单词带连字符时,其\hfill工作方式与往常不同:

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

我应该写什么才能获得像示例中\hfill第一个那样的工作?\hfill

答案1

第一个解决方案是我的解决方案的修改如果没有空间,则将右对齐的文本移至下一行

我还展示了大卫的解决方案,以便了解它可能在哪些地方失败。

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

在此处输入图片描述

答案2

这种行为实际上与连字符无关,但我认为您只是想避免最后一个短语超过一行,因此:

在此处输入图片描述

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

你可以用这个来制作一个宏(并解决 egreg 的观点)

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

在此处输入图片描述

相关内容