當我使用\hfill
and 在前一行中最後一個單字用連字符連接時,其\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}