带有多行和下划线文本的颜色框​​(在段落内)

带有多行和下划线文本的颜色框​​(在段落内)

在段落中,我想用颜色框突出显示文本的某些部分(不是整个段落!),并在该颜色框内的文本下划线。这就是我想要的结果:

在此处输入图片描述

我可以执行以下操作:

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{color,soul}
\usepackage[normalem]{ulem}
%%%%%
% Colorboxed and underlined text (one line)
\newcommand{\tp}[1]{\colorbox{yellow}{\setulcolor{blue}\ul{#1}}}

\begin{document}
This is the beginning of the paragraph, and now I am interested in 
\tp{highlighting a couple of lines of this paragraph with both underlined text
and a colorbox}. If I want to highlight just a couple of words in the same line,
 \tp{I can use this}. But it does not work when interested in highlighting 
multiple lines, because the line does not break.
\end{document}

但是(多行)突出显示的文本在页面末尾没有换行! 因此,我尝试了以下方法:

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{color,soul} % Para colored underlined
\usepackage[normalem]{ulem}

%%%%
%  Colorboxed and underlined text (one line)
\newcommand{\tp}[1]{%
    \begingroup
    \setulcolor{blue}
    \sethlcolor{yellow}
    \hl{\ul{#1}}
    \endgroup
}

\begin{document}
This is the beginning of the paragraph, and now I am interested in 
\tp{highlighting a couple of lines of this paragraph with both underlined text 
and a colorbox}. Here my paragraph ends.
\end{document}

但它不起作用...发生了一些错误。你知道我应该怎么做才能在段落中间的颜色框内添加下划线文本吗?

我希望我的问题足够清楚... :/

提前致谢!

答案1

运行lualatex

\documentclass{article}
\usepackage{xcolor,luacolor}
\usepackage[soul]{lua-ul}
\newcommand\ulcol[2][black!15]{\highLight[#1]{\ul{#2}}}
\begin{document}
    Lots of stuff is \ulcol{important enough to be highlighted,
    but only few things are dangerous enough to deserve}
    \ulcol[red]{red highlighting.
    Let's go back to traditional highlighting}.
\end{document}

在此处输入图片描述

答案2

灵魂手册(§22)说灵魂命令不能嵌套。不过,建议使用盒子的解决方案对你没有帮助,因为

“那当然就不会被打破了。”

此外,只有当你想通过在同一文本上加下划线和高亮来同时表达两种不同的东西时,你才应该只选择其中一种方式。这样更有意义,读者看起来也更好。

相关内容