8

Is it possible to use different rounded corners radii on different parts of a draw command?

I'm creating a tube that is bent. I'd like the outer radius to be greater than the inner radius. I can of course do this by creating two different draw commands, but then I won't be able to fill the object.

\filldraw[draw=blue!50, fill=black!10, rounded corners=2] (1.9,15) -- (3.1,15) -- (3.1,14.6)
-- (3.3,14.6) -- (3.3,15.2) -- (3.5,15.2)-- (3.5,13.9) -- (3.3,13.9) --(3.3,14.5) --
(3.1,14.5) -- (3.1,14.1) -- (1.9,14.1) -- cycle;

I've tried the following, but it generated a white diamond-shape in the middle of the figure that was supposed to be green.

\documentclass[border=3mm]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\filldraw node[fill=green,
append after command={[rounded corners=0pt](b.west)|-(b.north)},
append after command={[rounded corners=3pt](b.north)-|(b.east)},
append after command={[rounded corners=1pt](b.east)|-(b.south)},
append after command={[rounded corners=5pt](b.south)-|(b.west)}] (b) {Another piece of text};
\end{tikzpicture}

\end{document}
Hugo
  • 907

1 Answers1

10

Yes, the rounded corners key can be specified at several points along the path with different values by adding [rounded corners=<value>] in the path, which will then be active until the end of the path or until the next rounded corners key. Alternatively, as Qrrbirlbel pointed out in a comment, you can also keep the option local to part of the path by enclosing it in { ... }. I've used both approaches in the example below:

\documentclass[border=5mm]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\filldraw[draw=blue!50, fill=black!10, rounded corners=3] (1.9,15)
-- (3.1,15) {[rounded corners=1]
-- (3.1,14.6) 
-- (3.3,14.6)}
-- (3.3,15.2)
-- (3.5,15.2)
-- (3.5,13.9)
-- (3.3,13.9) [rounded corners=1]
-- (3.3,14.5)
-- (3.1,14.5) [rounded corners=3]
-- (3.1,14.1) -- (1.9,14.1) -- cycle;
\end{tikzpicture}
\end{document}
Jake
  • 232,450
  • 1
    Is there a list of settings which can be used this way? It doesn't work for line width or line color I assume. – Stephan Lehmke Feb 19 '13 at 19:06
  • 1
    @StephanLehmke: Ah, that would be useful indeed. No, it doesn't work for colour, width, line join, or most other options. I think it only works for things that have more to do with path construction (radius for circles, for example) than with the actual path representation. – Jake Feb 19 '13 at 19:11
  • 2
    @StephanLehmke Unfortunately, the PGF manual is very unspecific about that (section 14: “Some options […]”). @Jake you might add, that this option can also be “scoped” which removes the need to repeat rounded corners=3, e.g. \path[rounded corners=3] <radius is 3> { [rounded corners=1] <radius is 1> } <radius is 3 again>;. – Qrrbrbirlbel Feb 19 '13 at 19:23
  • @Qrrbrbirlbel: Good point! I've edited my answer. Thanks! – Jake Feb 19 '13 at 23:36