我正在使用 ulem 包按照这里的建议执行干净的下划线 https://alexwlchan.net/2017/10/latex-underlines/
它非常有效,但无论字体大小如何,线条的粗细都保持不变。
作为第一次尝试,我希望当字体设置为 HUGE(使用 moresize 包的最大尺寸)时,参数能够相应地改变。
但是,当我尝试使用它时,我收到一条错误消息“未定义的控制序列”。
% !TEX TS-program = lualatex
\documentclass[fontsize=12pt,DIV=calc,oneside]{scrarticle}
\usepackage{contour}
\usepackage[normalem]{ulem}
\usepackage{moresize}
% Underline
\makeatletter
\newcommand{\cleverul}[1]
{%
\ifthenelse{\equal{\f@size}{\pointsize{\normalsize}}}%
{%
\setlength{\ULdepth}{1.8pt}%
\renewcommand{\ULthickness}{0.8pt}%
\uline{\phantom{#1}}%
\llap{\contour{white}{#1}}%
}%
\ifthenelse{\equal{\f@size}{\pointsize{\HUGE}}}%
{%
\setlength{\ULdepth}{3pt}%
\renewcommand{\ULthickness}{1.5pt}%
\uline{\phantom{#1}}%
\llap{\contour{white}{#1}}
}%
}%
\makeatother
\begin{document}
\cleverul{try}
\end{document}
答案1
您可以使用简单的计算来代替检测:
\documentclass[fontsize=12pt,DIV=calc,oneside]{scrarticle}
\usepackage{contour}
\usepackage[normalem]{ulem}
\usepackage{moresize}
\usepackage{fp}
% Underline
\contourlength{0.8pt} % Specifies the distance between the underline and the character parts it does not want to touch.
\makeatletter
\newcommand{\cleverul}[1]
{%
\FPmul\cleverul@temp{\f@size}{0.15}% This is \f@size * 0.15
\setlength{\ULdepth}{\cleverul@temp pt}%
\FPdiv\cleverul@temp{\f@size}{15}% This is \f@size / 15
\renewcommand{\ULthickness}{\cleverul@temp pt}%
\uline{\phantom{#1}}%
\llap{\contour{white}{#1}}%
}%
\makeatother
\begin{document}
\noindent\cleverul{try}
\HUGE
\noindent\cleverul{try}
\end{document}
与 Biblatex 中的 URL 配合使用效果很好,只需添加以下行:
\DeclareFieldFormat{url}{\cleverul{\url{#1}}} % Without the word URL.
或者
\DeclareFieldFormat{url}{\mkbibacro{URL}\addcolon\space\cleverul{\url{#1}}} % With the word URL.
答案2
您可以简单地设置\ULthickness
为字体相关的长度:
\documentclass[fontsize=12pt,DIV=calc,oneside]{scrarticle}
\usepackage{fix-cm}
\usepackage{contour}
\usepackage[normalem]{ulem}
\usepackage{moresize}
\renewcommand\ULthickness{.04em}
\begin{document}
\raggedright
{\tiny \uline{try \the\dimexpr\ULthickness}}
\uline{try \the\dimexpr\ULthickness}
{\huge \uline{try \the\dimexpr\ULthickness}}
{\HUGE \uline{try \the\dimexpr\ULthickness}}
\end{document}
答案3
这不是很美丽吗?
\documentclass[fontsize=12pt,DIV=calc,oneside]{scrarticle}
\usepackage{moresize}
\usepackage{contour}
\usepackage[normalem]{ulem}
\usepackage{fp}
% Clever Underline
\makeatletter
\newcommand{\cleverul}[1]
{%
\FPmul\cleverul@temp{\f@size}{0.15}% This is \f@size * 0.15
\setlength{\ULdepth}{\cleverul@temp pt}%
\FPdiv\cleverul@temp{\f@size}{15}% This is \f@size / 15
\renewcommand{\ULthickness}{\cleverul@temp pt}%
\uline{\phantom{#1}}%
\llap{\contour{white}{#1}}%
}%
\makeatother
\begin{document}
\noindent\tiny I want to give a \cleverul{try}\\
\scriptsize I want to give a {\cleverul{try}}\\
\footnotesize I want to give a \cleverul{try}\\
\small I want to give a \cleverul{try}\\
\normalsize I want to give a \normalsize\cleverul{try}\\
\large I want to give a \cleverul{try}\\
\Large I want to give a \cleverul{try}\\
\LARGE I want to give \cleverul{try}\\
\Huge I want to give a \cleverul{try}\\
\HUGE I want to give a \cleverul{try}\\
\end{document}