新的“ulem”命令不起作用

新的“ulem”命令不起作用

我正在尝试创建一个新命令,该命令会在黑色文本下添加蓝色下划线。我的 mwe 是

\documentclass[a4paper,12pt]{report}
\usepackage[table,hyperref,dvipsnames]{xcolor}
\usepackage{ulem}
\newcommand{\coline}{\subsection{\textcolor{blue!80!black}\uline}} 
\begin{document}

\coline{the cat sat on the mat}
\end{document}

但它失败的说法

! Argument of \UL@on has an extra }.
<inserted text> 
                \par 
l.11 \coline
            {the cat sat on the mat}
? 

我正在使用xelatex它来处理它。请问我该如何让它工作?

我刚刚尝试过这个,但是它仍然不起作用。

\newcommand{\coline}{\textcolor{blue!80!black}\uline{\subsection}} 

答案1

是的\textcolor{color}{argument},而且\uline{argument}这里没有任何参数,所以宏会选择它们能找到的任何东西作为参数。

\documentclass[a4paper,12pt]{report}
\usepackage[table,hyperref,dvipsnames]{xcolor}
\usepackage{ulem}
\newcommand{\coline}[1]{\subsection{\textcolor{blue!80!black}{\uline{#1}}}}
\begin{document}
\chapter{}
\section{}

\coline{the cat sat on the mat}
\end{document}

在此处输入图片描述

答案2

为了好玩,这里有一个censor替代方案,带有一点小技巧。

\documentclass{article}
\usepackage{censor,xcolor}
%%%%%%%%%%%
\censorruleheight=.1ex %THICKNESS OF CENSOR RULE
\newlength\nextcharwidth
\makeatletter
\renewcommand\@cenword[1]{%
  \setlength{\nextcharwidth}{\widthof{#1}}%
  \textcolor{\ulinecolor}{\censorrule{\nextcharwidth}}%
  \kern -\nextcharwidth%
  \textcolor{black}{#1}}
\makeatother
\newcommand\couline[2][black]{%
  \def\ulinecolor{#1}%
  \censorruledepth=-.67ex\relax\color{#1}\xblackout{#2}\color{black}%
}
\newcommand\coline[2][blue!80!black]{\subsection{\protect\couline[#1]{#2}}}
%%%%%%%%%%%

\begin{document}
\coline{the cat sat on the mat}

Now I will test a multiline title

\coline[red]{the cat sat on the mat the cat sat on the mat the cat sat on the mat}

\large\couline[cyan]{the very large cat indeed sat on the mat. Once upon a 
time, the cat sat on the mat the cat sat on the mat}
\end{document}

在此处输入图片描述

答案3

从 ulem 包手册中,假设您的正常文本是黑色,请将其放在序言中:

\usepackage[normalem]{ulem}
\newcommand\blueuline{\bgroup\markoverwith{\textcolor{blue}{\rule[-0.75ex]{2pt}{1.5pt}}}\ULon}

您可能需要视觉上调整参数\rule

\documentclass{standalone}

\usepackage{xcolor}
\usepackage[normalem]{ulem}
\newcommand{\blueuline}{\bgroup\markoverwith{\textcolor{blue}{\rule[-0.75ex]{2pt}{1.5pt}}}\ULon}

\begin{document}
Here is some text. \blueuline{Here is some underlined text}
\end{document}

在此处输入图片描述

答案4

您可以使用 Hugh 的代码来titlesec使subsections 看起来像您想要的那样。方法如下。

\documentclass[a4paper,12pt]{report}
\usepackage[table,hyperref,dvipsnames]{xcolor}
\usepackage[normalem]{ulem}
\newcommand{\blueuline}{\bgroup\markoverwith{\textcolor{blue}{\rule[-0.75ex]{2pt}{1.5pt}}}\ULon}

\usepackage{titlesec}
\newcommand{\mysec}[1]{\blueuline{#1}}

\titleformat{\subsection}
{\normalfont\large\bfseries}{\thesubsection}{1em}{\mysec}

\begin{document}
\chapter{}
\section{}
\subsection{Here is some text Here is some text Here is some text Here is some text Here is some text}
\end{document}

在此处输入图片描述

相关内容