我在表格中有一個很長的文本,它由兩個命令組合而成,中間有一個空格,必須加下劃線。如何在加底線的同時使其換行?
下面的範例顯示了 \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