淡化 tikz 节点的背景

淡化 tikz 节点的背景

在 TikZ 图片中,我将文本节点放在深色背景上。为了增强可见性,我想使节点后面的背景变亮,而不管它是什么。因此,如果变亮的区域没有清晰的边界,而是淡出,那就太好了。

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% dark background:
\fill[black!0.8] (0,0) circle (1);
% this would also put light gray behind the node if the background is white:
\node[fill=light gray] at (0,0) {x};
% this kind of does what I want, but it would be nice if the lightening faded out:
\node[preaction={fill=white,opacity=0.5,blend mode=screen}] at (0,0) {x};
\end{tikzpicture}
\end{document}

答案1

当尝试创建 MWE 时,我偶然发现了一个解决方案(之前并不知道淡入淡出库是如何工作的):

\documentclass[tikz]{standalone}
\usetikzlibrary{fadings}
\tikzfading[name=fade out, inner color=black!40, outer color=black]
\begin{document}
\begin{tikzpicture}
% dark background:
\fill[black!80] (0,0) rectangle (1,1);
% nodes with lightened background
\node[circle, fill=white, inner sep=0.5,path fading=fade out] at (0.5,0.5) {x};
\node[circle, fill=white, inner sep=0.5,path fading=fade out] at (0.5,1) {x};
\end{tikzpicture}
\end{document}

如果您知道更好的方法,或者这样做是否有问题,请告诉我。另外,是否可以在不在\tikzfading文档中的其他地方定义的情况下执行此操作? 在此处输入图片描述

答案2

像这样(遵循 Andi Bauer 的解决方案):

在此处输入图片描述

代码:

\documentclass[tikz]{standalone}
\usetikzlibrary{fadings}
\tikzfading[name=fade out, inner color=black!40, outer color=black]
\begin{document}
    \begin{tikzpicture}
        % dark background
        \fill[black!80] (0,0) rectangle (3,3);
        % nodes with lightened background
        \draw[fill=white, path fading=fade out] (1.5,2) circle(.5) node () {x};
        \draw[fill=white, path fading=fade out] (1.5,1) circle(.5) node () {x};
    \end{tikzpicture}
\end{document}

相关内容