我的表格中有一段很长的文本,它由两个命令组合而成,中间有一个空格,需要加下划线。我怎样才能让它在加下划线的同时换行?
下面的例子展示了 \underline、\uline 和 \ul 的行为。
例子:
\documentclass{article}
\usepackage{tabularx}
\usepackage{soul}
\usepackage[normalem]{ulem}
\newcommand{\texta}{{Short text from some command.}}
\newcommand{\textb} {{Long text from some other command. This text should be broken on line end and not overflow.}}
\soulregister{\texta}{0}
\soulregister{\textb}{0}
\begin{document}
\begin{tabularx}{\textwidth}{|l|X|}
\hline
nothing & \texta\ \textb \\
\hline
underline & \underline{\texta\ \textb} \\ % Overflows
\hline
uline & \uline{\texta\ \textb} \\ % Overflows
\hline
ul & \ul{\texta\ \textb} \\ % Breaks line, but does not underline. Space is ignored.
\hline
\end{tabularx}
\end{document}
答案1
\ul
包中的命令确实soul
有效。但在使用它时会遇到两个问题。
\texta
1) 由于和的定义中多了一排括号,所以您的文本不会带有下划线\textb
。首先删除以下括号:
\newcommand{\texta}{Short text from some command.}
\newcommand{\textb}{Long text from some other command. This text should be broken on line end and not overflow.}
2)你应该扩展论点\ul
:
\edef\myulcmd{\noexpand\ul{\unexpanded\expandafter{\texta}\space\unexpanded\expandafter{\textb}}}%
\myulcmd