这篇文章是对如何用颜色连续阴影化段落的一部分
考虑一下代码
\documentclass{book}
\usepackage{xcolor}
\colorlet{soulred}{red!25}
\usepackage{tikzpagenodes}
\usetikzlibrary{tikzmark,calc}
\newlength{\markheight}
\begin{document}
\thispagestyle{empty}
\large
\begin{tikzpicture}[overlay, remember picture]
\coordinate (A) at (pic cs:start);
\coordinate (B) at (pic cs:end);
\pgfextracty{\markheight}{\pgfpointdiff{\pgfpointanchor{B}{center}}{\pgfpointanchor{A}{center}}}% difference in baselines
\ifdim\markheight<\baselineskip% same line
\fill[color=soulred] ($(A)+(-2pt,\ht\strutbox)$) rectangle ($(B)+(2pt,-\dp\strutbox)$);
\else
\ifdim\markheight<3\baselineskip
\fill[color=soulred] ($(A)+(-2pt,\ht\strutbox)$) rectangle ($(A -| current page text area.east)+(2pt,-\dp\strutbox)$);
\fill[color=soulred] ($(B -| current page text area.west)+(-2pt,\ht\strutbox)$) rectangle ($(B)+(2pt,-\dp\strutbox)$);
\else
\fill[color=soulred] ($(A)+(-2pt,\ht\strutbox)$) rectangle ($(A -| current page text area.east)+(2pt,-\dp\strutbox)$);
\fill[color=soulred] ($(A -| current page text area.west)+(-2pt,-\dp\strutbox)$) rectangle ($(B -| current page text area.east)+(2pt,\ht\strutbox)$);
\fill[color=soulred] ($(B -| current page text area.west)+(-2pt,\ht\strutbox)$) rectangle ($(B)+(2pt,-\dp\strutbox)$);
\fi
\fi
\end{tikzpicture}
Here is some text. \tikzmark{start}Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text.\tikzmark{end}
\vspace*{10pt}
Here is some text. \tikzmark{start}\textbf{Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text.}\tikzmark{end}
\end{document}
产生
我以通常的方式将彩色阴影文本加粗——通过将其应用于文本的特定部分——尽管它似乎抵消了第一段中命令\textbf
的使用。(不确定为什么。)\tikzmark
我有一份几百页的文档,除了对部分文本进行颜色阴影处理外,我还想将这些文本加粗。如果可能的话,我希望避免\textbf
在整个文档中多次使用这些颜色。
我希望能够有另一个命令(替代的命令\tikzmark
,比如类似于的命令\tikzmarkbold
),它可以对进行阴影处理\tikzmark
,但也会自动使阴影文本变为粗体。
我希望可以选择使用文档中的两个命令中的任一个。
问题:是否可以修改上述代码来实现这一点?如果可以,该如何做?
谢谢。