myuline 命令不接受换行符

myuline 命令不接受换行符

我在 Overleaf 上找到了一个模板,其中有以下几行代码:

\newcommand{\myuline}[1]{%
  \uline{\phantom{#1}}%
  \llap{\contour{white}{#1}}%
}

但是这个下划线命令会换行,我应该做什么修改呢?

答案1

我尝试修改 OP 指出的来自 overleaf 的函数模板\myuline。我已应用 egreg 的\makebox[0pt][r]{...}方法来替换,\llap{...}如中所述在 titleformat 中使用 llap 可防止换行。然而,问题仍然是文本没有像它应该的那样在打印空间的末尾断开。该\uline函数当然会在打印空间的末尾断开,但不会创建与文本底部齐平的下划线文本,并留有适合降部(如 g、p、y 等)的间隙。请参阅下面代码中的示例。


\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{comment}
\usepackage{contour}
\usepackage[showframe=true]{geometry}
\usepackage{titlesec}
\usepackage{ulem}

% See: "Four ways to underline text in LATEX" at \url{https://alexwlchan.net/2017/10/latex-underlines/}

\renewcommand{\ULdepth}{1.8pt}
\contourlength{0.8pt}

\newcommand{\myuline}[1]{%
  \uline{\phantom{#1}}%
  \llap{\contour{white}{#1}}%
}

% See: "Using llap in titleformat prevents line breaking" for egreg's answer on how to use '\makebox[0pt][r]{...}' to replace '\llap' at \url{https://tex.stackexchange.com/questions/277716/using-llap-in-titleformat-prevents-line-breaking}

\newcommand{\mXuline}[1]{%
  \uline{\phantom{#1}}%
  \makebox[0pt][r]{\contour{white}{#1}}%
}

\begin{document}

The \textbf{myuline} function provides a really nice underline, drawn on a consistent level, flush against the bottom of the text, with gaps as appropriate for descenders. However, it does NOT break at the end of the printing space where it should.\\

\textbf{myuline:} \myuline{A  happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long title}\\

The \textbf{mXuline} function (using egreg's \verb|\makebox[0pt][r]{...}| to replace \verb|\llap{...}|) provides a really nice underline, drawn on a consistent level, flush against the bottom of the text with gaps as appropriate for descenders. However, it ALSO does NOT break at the end of the printing space where it should.\\

\textbf{mXuline:} \mXuline{A happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long title}\\

The \textbf{uline} function underlines the text and it breaks at the end of the printing space where it should. However, uline does NOT draw the underline on a consistent level, flush against the bottom of the text, with gaps as appropriate for descenders.\\

\textbf{uline:} \uline{A happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long happy long title}\\

\textbf{Question: How can we create underline text flush against the bottom of the text, with gaps as appropriate for descenders, but that ALSO breaks at the end of the printing space where it should.}\\

 Normal text.
\end{document}

尝试用 \mXuline 替换 \myuline 以创建在打印空间末尾断开的下划线。

相关内容