![如何向图表中的节点添加阴影](https://linux22.com/image/418350/%E5%A6%82%E4%BD%95%E5%90%91%E5%9B%BE%E8%A1%A8%E4%B8%AD%E7%9A%84%E8%8A%82%E7%82%B9%E6%B7%BB%E5%8A%A0%E9%98%B4%E5%BD%B1.png)
我正在绘制一个图表。这是 MWE:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage{default}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\node[shape=circle,draw=black] (A) at (0,2) {A};
\node[shape=circle,draw=black] (B) at (0,0) {B};
\path (A) edge [loop above] node {} (A);
\path (B) edge [->] node[above] {} (A);
\end{tikzpicture}
\end{frame}
\end{document}
但我希望它看起来更像这样:
我怎样才能添加阴影并将箭头改为像第二幅图那样?
答案1
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, shadows}%<---------------add shadow
%\usepackage{default}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\node[shape=circle,draw=black,fill=white, drop shadow] (A) at (0,2) {A};
\node[shape=circle,draw=black,fill=white, drop shadow] (B) at (0,0) {B};
\path (A) edge [loop above] node {} (A);
\path (B) edge [->] node[above] {} (A);
\end{tikzpicture}
\end{frame}
\end{document}
编辑——为了更好地控制阴影
您还可以通过在 [] 中任何节点的选项中添加以下行来更好地控制颜色阴影
drop shadow={top color=green,
bottom color=yellow!40,
shadow xshift=4pt,
shadow yshift=-4pt,}
类似地,xshift 和 yshift 可以更精确地控制阴影的位置
下面是一个例子——注意——阴影也可以应用于箭头
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, shadows, shadows.blur}
%\usepackage{default}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\node[shape=circle,
draw=black,
fill=white,
drop shadow={top color=blue,
bottom color=blue!40,
shadow xshift=2pt,
shadow yshift=-2pt,},
% blur shadow={shadow blur steps=1}
]
(A) at (0,2) {A};
\node[shape=circle,
draw=black,
fill=white,
drop shadow={top color=green,
bottom color=yellow!40,
shadow xshift=4pt,
shadow yshift=-4pt,},
% blur shadow={shadow blur steps=1}
]
(B) at (0,0) {B};
\path (A) edge [loop above] node {} (A);
\path (B) edge [->] node[above] {} (A);
\end{tikzpicture}
\end{frame}
\end{document}