Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to fill a custom shaped node but as can be observed in the example below the fill does not occur naturally rather it uses its default shape to fill. Any insights?

\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}

enter image description here

share|improve this question
2  
I would go with Roelof's shape if compared to Ignasi's ;) –  percusse Mar 6 '13 at 0:19
    
Link to question where sample code was gotten is: tex.stackexchange.com/q/32867/10898 –  azetina Mar 6 '13 at 0:25
add comment

1 Answer 1

up vote 8 down vote accepted

Insight: The fill is used for the actual rectangle shape. The append after command is just appended to the path and uses the style of the \draw (no filling).

Although Roelof Spijker has given an excellent solution, here’s a fix by using one full path.

Code

\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}

Output

enter image description here

share|improve this answer
    
What does \pgfextra do? –  azetina Mar 6 '13 at 1:28
    
@azetina The PGF manual tells us (note that \pgfextra{<code>} and \pgfextra <code> \endpgfextra is the same): “This command may only be used inside a TikZ path. There it is used like a normal path operation. The construction of the path is temporarily suspended and the <code> is executed. Then, the path construction is resumed.” The append after command entry will be used in the middle of a path and this would result in an error as we would have had \draw <stuff> \draw <inner stuff>; <other stuff>;. –  Qrrbrbirlbel Mar 6 '13 at 1:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.