答案1
快速适应这一点回答对链接问题的回答是:
\documentclass{article}
\usepackage{lipsum}%dummy text only
\usepackage{tikz}
\usetikzlibrary{fadings}
\newcommand{\gradient}{\noindent%
\begin{tikzpicture}
\fill[black,path fading=west] (-0.5\linewidth,0) rectangle (0,1ex);
\fill[black,path fading=east] (0,0) rectangle (0.5\linewidth,1ex);
\end{tikzpicture}%
}
\begin{document}
\lipsum[1]
\gradient{}
\lipsum[2]
\end{document}
答案2
这是另一个版本,它使用各种 pgf 键控制规则的外观并一次性绘制出它。
\documentclass{article}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{fadings}
\tikzfading[name=fade out,
left color=transparent!100,right color=transparent!100,
middle color=transparent!0]
\tikzset{faded rule style/.style={},faded rule/.cd,color/.initial=black,width/.initial=\textwidth,
height/.initial=1ex,style/.code=\tikzset{faded rule style/.style={#1}}}
\newcommand{\FadeRule}[1][]{\noindent\tikz{\def\pv##1{\pgfkeysvalueof{/tikz/faded rule/##1}}
\tikzset{faded rule/.cd,#1}
\path(-\textwidth/2,0) -- (\textwidth/2,0);
\fill[faded rule style,color=\pv{color},path fading=fade out] (-\pv{width}/2,-\pv{height}/2)
rectangle (\pv{width}/2,\pv{height}/2);}}
\begin{document}
\lipsum[1]
\FadeRule
\lipsum[2]
\FadeRule[color=blue,height=1em]
\lipsum[3]
\FadeRule[color=red,width=0.7\textwidth]
\lipsum[3]
\FadeRule[style={opacity=0.5}]
\end{document}