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}
5
  • Possible duplicate of TikZ rectangular node with different rounded corners Feb 19, 2013 at 18:43
  • If the above linked question does not solve your issue, please update the question as to why. Otherwise this will probably be closed as a duplicate. Feb 19, 2013 at 18:44
  • @PeterGrill Even if I use the method described in the answer to the question linked, I still can't use filldraw as far as I can tell. If I would't fill the shape the other solution would work.
    – Hugo
    Feb 19, 2013 at 18:52
  • Oh, that didn't format very well. How am I supposed to give you the code?
    – Hugo
    Feb 19, 2013 at 21:45
  • @Hugo At the bottom of your question is an “Edit” button. You can add this code to your question. A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). Also, please add @<user> to your comment (as I did in mine) so that the author of the comment you’re responding to will be notified. Feb 20, 2013 at 0:11

1 Answer 1

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}
4
  • 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. Feb 19, 2013 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, 2013 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>;. Feb 19, 2013 at 19:23
  • @Qrrbrbirlbel: Good point! I've edited my answer. Thanks!
    – Jake
    Feb 19, 2013 at 23:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .