![如何在表格中加入底線文字換行?](https://rvso.com/image/390923/%E5%A6%82%E4%BD%95%E5%9C%A8%E8%A1%A8%E6%A0%BC%E4%B8%AD%E5%8A%A0%E5%85%A5%E5%BA%95%E7%B7%9A%E6%96%87%E5%AD%97%E6%8F%9B%E8%A1%8C%EF%BC%9F.png)
我在表格中有一個很長的文本,它由兩個命令組合而成,中間有一個空格,必須加下劃線。如何在加底線的同時使其換行?
下面的範例顯示了 \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