如何在 ulem 下划线环境中将注释 + 文本保留到行末?

如何在 ulem 下划线环境中将注释 + 文本保留到行末?

代码

% https://tex.stackexchange.com/a/159996/13173
\documentclass{article}
\usepackage[normalem]{ulem}
\begin{document}
\begin{enumerate}
\item Initials: \uline{A.B.C.} 
\item Age: \uline{50}
\item Address: \uline{Tampere}
\item Condition: \uline{ % showing where \uline{ \hfill\null}} 

      Entered text here in many lines. % I have also here many comments which causes problems

      It can go on many lines. % commments can be here

      \hfill\null}
\end{enumerate}
\end{document}

图 1 当前输出,图 2 右侧超载文本的复杂化

在此处输入图片描述

在此处输入图片描述

希望的输出:下划线穿过整个线宽,但不超过右侧边距

由于ulem环境中有评论,TeXLive 2017 中的输出

(/usr/local/texlive/2017/texmf-dist/tex/generic/ulem/ulem.sty) (./test.aux)
Runaway argument?
\@empty 
! Paragraph ended before \UL@word was complete.
<to be read again> 
                   \par 
l.15       \hfill\null}

? 
! Emergency stop.
<to be read again> 
                   \par 
l.15       \hfill\null}

测试 Ian 的回答

有关下划线文本穿过右侧边缘的复杂情况,请参见图 2。

操作系统:Debian 8.7 64 位
TeXLive:2017
引擎:Pdflatex
硬件:Asus Zenbook UX303UA

答案1

那这个呢?

\documentclass{article}
\usepackage[normalem]{ulem}



\begin{document}
\newcommand*{\newlinecommand}[2]{%
  \newcommand*{#1}{%
    \begingroup%
    \escapechar=`\\%
    \catcode\endlinechar=\active%
    \csname\string#1\endcsname%
  }%
  \begingroup%
  \escapechar=`\\%
  \lccode`\~=\endlinechar%
  \lowercase{%
    \expandafter\endgroup
    \expandafter\def\csname\string#1\endcsname##1~%
  }{\endgroup#2\par\space}%
}

%%% USAGE:
\newlinecommand{\myunder}{\uline{#1\hfill\null}}

\begin{enumerate}
\item First words \myunder rest Of line 
some More text not underlined
\item \myunder test 
%comment here
\myunder test2 on other line underlined %comment before empty line

test3 after paragraph not underlined
\item \myunder test3 befor a comment %comment

\myunder continue in new paragraph underlined
\item \myunder test4
%coment again
\myunder last line underlined
\end{enumerate}

\end{document}

它产生了这个: 这

我已经用过这个https://tex.stackexchange.com/questions/1042/def-taking-rest-of-the-line-as-argument答案......我认为用这种方式工作更舒服,即使它不完全是你想要的(因为你需要在每一行中使用新的下划线命令 - 但我认为这很好 -)

答案2

像这样?

\documentclass{article}
\usepackage[normalem]{ulem}
\begin{document}
\begin{enumerate}
\item Initials: \uline{A.B.C.\hfill\null}
\item Age: \uline{50\hfill\null}
\item Address: \uline{Tampere\hfill\null}
\end{enumerate}
\end{document}

答案3

删除环境中的注释\uline{...}。否则,方法与正文中相同。我认为环境不支持它们。

Heiko 向soul's求婚ul

代码

\documentclass{article}
\usepackage{soul}
\begin{document}
\begin{enumerate}
\item Initials: \ul{A.B.C.}
\item Age: \ul{50}
\item Address: \ul{Tampere}
\item Condition: \ul{ % showing where \uline{ \hfill\null}} 

      Entered text here in many lines. % I have also here many comments which causes problems

      It can go on many lines. % commments can be here

      \hfill\null}
\end{enumerate}
\end{document}

图 1 中的输出未完成行尾要求,但适用于段落(注释)+空行被视为空行,但事实并非如此:单个_

图 1 输出

在此处输入图片描述

相关内容