是否有与该ulem
包类似的包(或颜色 ulem),其中带有颜色、下划线、sout、xout、破折号下划线、点下划线以及颜色作为参数?
我发现这是有关使用 ulem 更改特殊下划线颜色的问答几个月前,我喜欢这个解决方案,但我想:
- 颜色作为参数
- sout、xout、破折号下划线和点下划线效果很好。
- 甚至可以与段落配合使用
\documentclass{article}
\usepackage{lipsum}
\usepackage[normalem]{ulem}
\usepackage[names]{xcolor}
\usepackage{amsmath}
\makeatletter
\newcommand{\culine}[2]{%
\newcommand\temp@uline{\bgroup\markoverwith
{\textcolor{#1}{\rule[-0.5ex]{2pt}{0.4pt}}}\ULon}%
\temp@uline{#2}%
}
\newcommand{\cuuline}[2]{%
\UL@protected\def\temp@uuline{\leavevmode \bgroup
\UL@setULdepth
\ifx\UL@on\UL@onin \advance\ULdepth2.8\p@\fi
\markoverwith{\textcolor{#1}{\lower\ULdepth\hbox
{\kern-.03em\vbox{\hrule width.2em\kern1\p@\hrule}\kern-.03em}}}%
\ULon}%
\temp@uuline{#2}%
}
\newcommand{\cuwave}[2]{%
\UL@protected\def\temp@uwave{\leavevmode \bgroup
\ifdim \ULdepth=\maxdimen \ULdepth 3.5\p@
\else \advance\ULdepth2\p@
\fi \markoverwith{\textcolor{#1}{\lower\ULdepth\hbox{\sixly \char58}}}\ULon}
\font\sixly=lasy6 % does not re-load if already loaded, so no memory drain.
\temp@uwave{#2}%
}
\newcommand{\csout}[2]{%
\UL@protected\def\temp@sout{\leavevmode \bgroup
\ifdim \ULdepth=\maxdimen \ULdepth 3.5\p@
\else \advance\ULdepth2\p@
\fi \markoverwith{\textcolor{#1}{\lower\ULdepth\hbox{\sixly \char58}}}\ULon}
\font\sixly=lasy6 % does not re-load if already loaded, so no memory drain.
\temp@sout{#2}%
}
\newcommand{\cxout}[2]{%
\UL@protected\def\temp@uwave{\leavevmode \bgroup
\ifdim \ULdepth=\maxdimen \ULdepth 3.5\p@
\else \advance\ULdepth2\p@
\fi \markoverwith{\textcolor{#1}{\lower\ULdepth\hbox{\sixly \char58}}}\ULon}
\font\sixly=lasy6 % does not re-load if already loaded, so no memory drain.
\temp@uwave{#2}%
}
\newcommand{\cdashuline}[2]{%
\UL@protected\def\temp@uwave{\leavevmode \bgroup
\ifdim \ULdepth=\maxdimen \ULdepth 3.5\p@
\else \advance\ULdepth2\p@
\fi \markoverwith{\textcolor{#1}{\lower\ULdepth\hbox{\sixly \char58}}}\ULon}
\font\sixly=lasy6 % does not re-load if already loaded, so no memory drain.
\temp@uwave{#2}%
}
\newcommand{\cdotuline}[2]{%
\UL@protected\def\cdotuline{\leavevmode \bgroup
\UL@setULdepth
\ifx\UL@on\UL@onin \advance\ULdepth2\p@\fi
\markoverwith{\begingroup
%\advance\ULdepth0.08ex
\lower\ULdepth\hbox{\kern.06em \textcolor{#1}{.}\kern.04em}%
\endgroup}%
\ULon}
}
\UL@protected\def\greendashuline{\leavevmode \bgroup
\UL@setULdepth
\ifx\UL@on\UL@onin \advance\ULdepth2\p@\fi
\markoverwith{\kern.13em
\vtop{\color{green}\kern\ULdepth \hrule width .3em}%
\kern.13em}\ULon}
\makeatother
%
\begin{document}
%
\textbf{With Color:}
\culine{brown}{I am underlined in color.}
% \culine{red}{\lipsum[1].}
\cuuline{blue}{I am double underlined in color.}
% \culine{green}{\lipsum[1].}
\cuwave{teal}{I am underlined in waves.}
% \cuwave{blue}{\lorem[1].}
I am not underlined at all.
\csout{orange}{I am SOUTED in color}
\cxout{green}{I am XOUTED in color.}
\cdashuline{cyan}{I am dash-underlined in color.}
\cdotuline{red}{I am dot-underlined in color.}
\medskip
\par
\textbf{Without color: (works fine!)}
\uline{I am underlined in color.}
\uuline{I am double underlined in color.}
\uwave{I am underlined in waves.}
I am not underlined at all.
\sout{I am SOUTED in color}
\xout{I am XOUTED in color.}
\dashuline{I am dash-underlined in color.}
\dotuline{I am dot-underlined in color.}
\end{document}
答案1
嗯,你应该使用正确的宏原始定义。如果你使用宏\uwave
定义\cxout
,当然你会得到相同的波浪下划线...=)
此外,您不应\newcommand
在重新定义中使用,因为如果您尝试多次使用新定义的宏,这将引发错误。最好坚持使用\UL@protected\def
。
唯一不能通过插入某些\color
命令来简单编辑的宏是 for \sout
,但重新使用宏的定义\uline
并使用 移动行却相当容易\raisebox
。
\documentclass{article}
\usepackage{ulem}
\usepackage{xcolor}
\makeatletter
\newcommand{\culine}[2]{%
\UL@protected\def\temp@uline{\bgroup\markoverwith
{\textcolor{#1}{\rule[-0.5ex]{2pt}{0.4pt}}}\ULon}%
\temp@uline{#2}%
}
\newcommand{\cuuline}[2]{%
\UL@protected\def\temp@uuline{\leavevmode \bgroup
\UL@setULdepth
\ifx\UL@on\UL@onin \advance\ULdepth2.8\p@\fi
\markoverwith{\textcolor{#1}{\lower\ULdepth\hbox
{\kern-.03em\vbox{\hrule width.2em\kern1\p@\hrule}\kern-.03em}}}%
\ULon}%
\temp@uuline{#2}%
}
\newcommand{\cuwave}[2]{%
\UL@protected\def\temp@uwave{\leavevmode \bgroup
\ifdim \ULdepth=\maxdimen \ULdepth 3.5\p@
\else \advance\ULdepth2\p@
\fi \markoverwith{\textcolor{#1}{\lower\ULdepth\hbox{\sixly \char58}}}\ULon}
\font\sixly=lasy6 % does not re-load if already loaded, so no memory drain.
\temp@uwave{#2}%
}
\newcommand{\csout}[2]{%
\UL@protected\def\temp@sout{\bgroup\markoverwith
{\textcolor{#1}{\raisebox{1.05ex}{\rule[-0.5ex]{2pt}{0.4pt}}}}\ULon}%
\temp@sout{#2}%
}
\newcommand{\cxout}[2]{%
\UL@protected\def\temp@xout{\leavevmode \bgroup
\markoverwith{\color{#1}\hbox to.35em{\hss/\hss}}\ULon}%
\temp@xout{#2}%
}
\newcommand{\cdashuline}[2]{%
\UL@protected\def\temp@dashuline{\leavevmode \bgroup
\UL@setULdepth
\ifx\UL@on\UL@onin \advance\ULdepth2\p@\fi
\markoverwith{\kern.13em
\vtop{\color{#1}\kern\ULdepth \hrule width .3em}%
\kern.13em}\ULon}
\temp@dashuline{#2}%
}
\newcommand{\cdotuline}[2]{%
\UL@protected\def\temp@dotuline{\leavevmode \bgroup
\UL@setULdepth
\ifx\UL@on\UL@onin \advance\ULdepth2\p@\fi
\markoverwith{\begingroup
%\advance\ULdepth0.08ex
\lower\ULdepth\hbox{\kern.06em \textcolor{#1}{.}\kern.04em}%
\endgroup}%
\ULon}%
\temp@dotuline{#2}%
}
\makeatother
\begin{document}
\textbf{With Color:}
\culine{brown}{I am underlined in color.}
\cuuline{blue}{I am double underlined in color.}
\cuwave{teal}{I am underlined in waves.}
I am not underlined at all.
\csout{orange}{I am SOUTED in color}
\cxout{green}{I am XOUTED in color.}
\cdashuline{cyan}{I am dash-underlined in color.}
\cdotuline{red}{I am dot-underlined in color.}
\end{document}
允许不同厚度的变体:
\documentclass{article}
\usepackage{ulem}
\usepackage{xcolor}
\makeatletter
\newcommand{\cthickuline}[3][0.5pt]{%
\UL@protected\def\temp@uline{\bgroup\markoverwith
{\textcolor{#2}{\rule[-0.5ex]{2pt}{#1}}}\ULon}%
\temp@uline{#3}%
}
\makeatother
\begin{document}
\textbf{With Color:}
\cthickuline[0.1pt]{red}{I am underlined in color.}
\cthickuline{red}{I am underlined in color.}
\cthickuline[1.2pt]{red}{I am underlined in color.}
\end{document}