1

Consider the following LaTeX manuscript (the TikZ code is copied from the first example on p. 146 of the TikZ & PGF Manual for Version 3.0.1a):

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
  \draw (0,0) -- (1,1)
  [rounded corners] -- (2,0) -- (3,1)
  [sharp corners] -- (3,0) -- (2,1);
\end{tikzpicture}
\end{document}

Compiling this file with pdflatex produces the following pdf file:

A TikZ path with sharp and round corners.

Note that the corners don't change from sharp to round and vice versa immediately after the corresponding option is given, but rather starting with the next corner. How can I make the options apply immediately?

  • rounded corners need two points (previous and next) to understand how to round it. You can't apply it immediately without two points on the stack. – percusse Jul 4 '17 at 14:01
  • @percusse: But there are two points: (1,1) and (2,0). – Evan Aad Jul 4 '17 at 14:02
  • Yes (2,0) will be rounded (1,1) is the previous and how to find the out angle without (3,1)? – percusse Jul 4 '17 at 14:03
  • @percusse: Why can't the [rounded corners] option use the (0,0) and (1,1) points, just like the --(2,0) path operation uses the (1,1) point? – Evan Aad Jul 4 '17 at 14:04
  • @EvanAad presumably it doesn't have the 0,0 available as you hadn't told it to save enough information to round until later, – David Carlisle Jul 4 '17 at 14:16
2

The manual version 3.0.1a Section 14 says:

At any point where TikZ expects a path operation, you can also give some graphic options, which is a list of options in brackets, such as [rounded corners]. These options can have different effects: 1. Some options take “immediate” effect and apply to all subsequent path operations on the path. For example, the rounded corners option will round all following corners, but not the corners “before” and if the sharp corners is given later on the path (in a new set of brackets), the rounding effect will end.

When you place the rounded corners option right after the first line generated, it will not use the already generated line, but the intersection of the subsequent (following) two lines which are:

Line goes from (2,0) to (3,1)

Line goes from (3,1) to (3,0)

Therefore, if you want to apply it to the first line, you need to tell Tikz about it before it is generated.

  • Was it this simple or am I missing something? – berkus Jul 4 '17 at 14:30
  • Why is the corner at (1,1) considered before the [rounded corners] option? After all, at the point the option is given, there's no corner there yet! – Evan Aad Jul 4 '17 at 14:32
  • @evan rounded corner identifies the corner to be rounded with two intersection lines. It finds the intersection. And rounds it. Not a given point. – berkus Jul 4 '17 at 14:34
  • But there are two intersection lines: the one from (0,0) to (1,1), and the one from (1,1) to (2,0). Why doesn't the option make use of this information? Well, I guess it's a silly question: that's just how it's coded. I'll accept your answer. Still I wonder: could it have been coded differently so as to take advantage of this information, or is this information (namely the point (0,0)) not available to it so that it couldn't have taken it into account even if it wanted to? – Evan Aad Jul 4 '17 at 14:37
  • @Evan Well that is how it is coded as it is explained in the manual. – berkus Jul 4 '17 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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