
我非常清楚這被認為是最佳實踐不是在打字機和手寫體以外的地方使用底線。但有時仍然需要它。
在我看來,在印刷中劃線在印刷上最不令人反感的方式是省略下行部分。這也是我學會手寫的方法。很少有字體提供預製的下劃線變體,但一些文字處理器(例如 OS X 文字引擎)在模擬這種效果方面確實可以接受,具體取決於所使用的字體:
我將如何調整現有的底線方法/套件來執行相同的操作?
作為獎勵,我希望能夠調整每個字體和文字樣式的行為(省略部分的範圍,適用於哪些字母),最好使用 XeLaTeX。
答案1
我們可以對每個字母做:
- 產生底線
- 使用相同但更粗的字母或左右移動的字母覆蓋該行,但背景色或白色
- 寫信
所以我們會得到一個有匹配間隙的下劃線。
這裡我soul
這樣修改了Marco的方法,只是為了示範我的意思,可以改進(粗體,循環):
\setcounter{errorcontextlines}{999}
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{soul}
\usepackage{color}
\makeatletter
\newcommand*{\whiten}[1]{\llap{\textcolor{white}{{\the\SOUL@token}}\hspace{#1pt}}}
\DeclareRobustCommand*\myul{%
\def\SOUL@everyspace{\underline{\space}\kern\z@}%
\def\SOUL@everytoken{%
\setbox0=\hbox{\the\SOUL@token}%
\ifdim\dp0>\z@
\raisebox{\dp0}{\underline{\phantom{\the\SOUL@token}}}%
\whiten{1}\whiten{0}%
\whiten{-1}\whiten{-2}%
\llap{\the\SOUL@token}%
\else
\underline{\the\SOUL@token}%
\fi}%
\SOUL@}
\makeatother
\begin{document}
\sffamily\Huge
\myul{jumping quickly}
\end{document}
答案2
contour
這是使用和包的解決方案ulem
。
IMO 這會產生一個非常漂亮的下劃線,特別是標題下劃線:
\documentclass{article}
\usepackage[outline]{contour}
\usepackage{ulem}
\normalem % use classical emph
\newcommand \myul[4]{%
\begingroup%
\renewcommand \ULdepth {#1}%
\renewcommand \ULthickness {#2}%
\contourlength{#3}%
\uline{\phantom{#4}}\llap{\contour{white}{#4}}%
\endgroup%
}
\newcommand \myulline[4]{%
\begingroup%
\renewcommand \ULdepth {#1}%
\renewcommand \ULthickness {#2}%
\contourlength{#3}%
\noindent\rlap{\uline{\hspace{\textwidth}}}\contour{white}{#4}%
\endgroup%
}
\begin{document}
\bfseries
\Huge
\myulline{5pt}{1pt}{2pt}{Chapter Eight}
\vspace{1cm}
\normalsize
\normalfont
Test. \myul{2pt}{0.5pt}{1pt}{Quit jumping quickly!} Test.
Test. \myul{1.2pt}{0.5pt}{0.5pt}{Quit jumping quickly!} Test.
\end{document}
輸出:
特寫:
缺點是,下劃線深度不能非常接近基線,因為它可能被輪廓隱藏。
答案3
只是因為我發現它在這裡很有用,這是對上面 Stefans 答案的修改,可以讓你控制底線的深度、厚度和寬度。例如,對於更大或更粗的字體,這可能很有用。語法為: \varul<width>[depth][thickness]{stuff}
其中:
<width>
是可選的,並以 的倍數給出1/100 em
,例如<10>
將給出間隙寬度0.1em
。預設值為5
[depth]
是可選的,並以正值(包括單位)給出,指定繪製下劃線的基線下方的距離。預設值為0.2ex
。[thickness]
是可選的,並以正值(包括單位)給出,指定下劃線的粗細。預設值為0.1ex
- 第四個強制參數是您想要強調的內容。
這將適用於段落和換行符,但可能會稍微改變間距。
\documentclass{article}
\usepackage{soul}
\usepackage{xcolor}
\usepackage{xparse}
\makeatletter
\ExplSyntaxOn
\cs_new:Npn \white_text:n #1
{
\fp_set:Nn \l_tmpa_fp {#1 * .01}
\llap{\textcolor{white}{\the\SOUL@syllable}\hspace{\fp_to_decimal:N \l_tmpa_fp em}}
\llap{\textcolor{white}{\the\SOUL@syllable}\hspace{-\fp_to_decimal:N \l_tmpa_fp em}}
}
\NewDocumentCommand{\whiten}{ m }
{
\int_step_function:nnnN {1}{1}{#1} \white_text:n
}
\ExplSyntaxOff
\NewDocumentCommand{ \varul }{ D<>{5} O{0.2ex} O{0.1ex} +m } {%
\begingroup
\setul{#2}{#3}%
\def\SOUL@uleverysyllable{%
\setbox0=\hbox{\the\SOUL@syllable}%
\ifdim\dp0>\z@
\SOUL@ulunderline{\phantom{\the\SOUL@syllable}}%
\whiten{#1}%
\llap{%
\the\SOUL@syllable
\SOUL@setkern\SOUL@charkern
}%
\else
\SOUL@ulunderline{%
\the\SOUL@syllable
\SOUL@setkern\SOUL@charkern
}%
\fi}%
\ul{#4}%
\endgroup
}
\makeatother
\begin{document}
\varul{\Huge jumping quickly}\par\smallskip
\varul[1pt][1pt]{\Huge jumping quickly}
\end{document}
托比編輯: \fp_mul:Nn
在當前的 TeXlive 中不起作用,所以我將這兩行替換為\fp_set:Nn \l_tmpa_fp {#1 * .01}
.
答案4
我使用 CDSousa 答案的以下改編版本,有兩個原因:首先,XCharter + 輪廓由於某種原因看起來比其他文字更粗糙;其次,允許使用閉合下劃線(CDSousa 指出的缺點):
\usepackage{ulem}
\normalem % use classical emph
\usepackage{color}
\usepackage{pgffor}
\newcommand\myul[4]{% arg 1: underline depth; arg 2: underline thickness; arg 3: space around descenders in pt (!)
\begingroup%
\renewcommand\ULdepth{#1}%
\renewcommand\ULthickness{#2}%
\uline{\phantom{\smash{#4}}}%
\foreach \hshift in {0.0, 0.1, ..., #3}{%
\foreach \upshift in {-0.4, -0.3, ..., 1.0}{%
\llap{\color{white}\raisebox{\upshift0pt}[0pt]{#4}\hspace{\hshift0pt}}%
\llap{\color{white}\raisebox{\upshift0pt}[0pt]{#4}\hspace{-\hshift0pt}}%
}%
}%
\llap{#4}%
\endgroup%
範例:\myul{1.75pt}{.5pt}{2}{Blupp of (that's \emph{of}, not \emph{off}, of course) a great Synopsis}
具有下劃線深度1.75pt
、底線厚度.5pt
和間距2pt
,看起來像