填充节点形状

填充节点形状

我正在尝试填充自定义形状的节点,但正如以下示例中所观察到的,填充不会自然发生,而是使用其默认形状进行填充。有什么见解吗?

\documentclass[letterpaper]{article}
\usepackage{tikz}

\usetikzlibrary{shapes.geometric,calc}

\setlength{\parindent}{0pt}

\begin{document}

\begin{tikzpicture}
\draw (0,0) -- (\textwidth-0.4pt, 0) node[
    fill=blue!20,
    append after command={[rounded corners=0pt](b.west)|-(b.north)},
    append after command={[rounded corners=0pt](b.north)-|(b.east)},
    append after command={[rounded corners=1pt](b.east)|-(b.south)},
    append after command={[rounded corners=5pt](b.south)-|(b.west)},
    anchor=north west,
    at start,
    text=white] 
(b) {Example} ;
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

洞察:fill用于实际rectangle形状。append after command只是附加到路径并使用 的样式\draw(无填充)。

虽然鲁洛夫·史派克给出了一个很好的解决方案,这里是使用一个完整路径的修复方法。

代码

\documentclass[letterpaper]{article}
\usepackage{tikz}

\setlength{\parindent}{0pt}

\tikzset{weird fill/.style={append after command={
    \pgfextra
        \draw[sharp corners, fill=#1] (\tikzlastnode.west) |- (\tikzlastnode.north east) [rounded corners=1pt] |- (\tikzlastnode.south) [rounded corners=5pt] -|  (\tikzlastnode.north west) -- cycle;
    \endpgfextra}}}
\begin{document}

\begin{tikzpicture}
\draw (0,0) -- (\textwidth-0.4pt, 0) node [
    weird fill=blue!20,
    anchor=north west,
    at start,
    text=white] {Example} ;
\end{tikzpicture}
\end{document}

输出

在此处输入图片描述

相关内容