1

I found a template on Overleaf in which I found the following lines of code:

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

However, this underline command is taking any line break, what modifications should I make?

3

1 Answer 1

1

I've attempted to modify what the OP indicated was a template from overleaf for the \myuline function. I've applied egreg's \makebox[0pt][r]{...} method to replace \llap{...} as explained in Using llap in titleformat prevents line breaking. The issue however remains that the text does not break at the end of the printing space as it should. The \uline function, of course breaks at the end of the printing space, but does NOT create underline text flush against the bottom of the text, with gaps as appropriate for descenders, such as g, p, y, etc. See the example in the code below.


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

Attempt to replace \myuline with \mXuline to create underline that breaks at the end of the printing space.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .