12

Background: When I draw a tikzpicture, I use only the default units (i.e. I do not specify any unit, as in \draw (0,0) -- (1,1);).

Issue: When no unit is given in the [rounded corners = <value>] option, TikZ seems to assume the given length is expressed in pt, i.e. not in the same unit than the default one. This phenomenon is highlighted in the example below. (This might be due to the fact that [rounded corners] = [rounded corners = 4pt]?)

enter image description here

\documentclass[margin=1cm]{standalone}
    \usepackage{tikz}

\begin{document}
    \begin{tikzpicture}[very thick]
        \draw [help lines, black!10] (-.5,-.5) grid (7.5,3.5);

        \draw [rounded corners=1] (0,0) rectangle ++(3,3) node [midway] {\footnotesize\texttt{rounded corners=1}};

        \draw [rounded corners=1cm] (4,0) rectangle ++(3,3) node [midway] {\footnotesize\texttt{rounded corners=1cm}};
    \end{tikzpicture}
\end{document}

Question: I would like to specify the radius of rounded corners as a multiple of the default unit (without assuming 1 default unit = 1cm). How can I achieve this?

ebosi
  • 11,692
  • The same issue occurs when you specify minimum height = 15 in \node [draw, single arrow] at (0,0) {}; (\usetikzlibrary{shapes.arrows} is needed for this). – ebosi Aug 02 '16 at 13:43
  • If you want consistency, add cm to everything. – John Kormylo Aug 02 '16 at 14:17
  • well, that's not very convenient... I'd be glad if there is a more flexible approach! – ebosi Aug 02 '16 at 14:32
  • The conversion to 1pt is done by latex, usually with an error message. The conversion to 1cm is done by the tikz path parser, – John Kormylo Aug 02 '16 at 14:41
  • Tikz uses its own parser. From \path to ; everything is being processed by tikz so normal latex rules do not apply. The options however are process by pgfkeys, although it appears the error message ! Illegal unit of measure (pt inserted) is suppressed. – John Kormylo Aug 02 '16 at 14:57

1 Answers1

12

Well, you can always save the default unit in a macro and write rounded corners=<number>\macroname. Or you could use a wrapper style definition which automates this. For example:

\documentclass[border=10pt,multi,tikz]{standalone}
\begin{document}
\tikzset{%
  ebo unit/.store in=\ebounit,
  ebo corners/.style={rounded corners=#1\ebounit},
}
\begin{tikzpicture}[very thick, ebo unit=cm]
  \draw [help lines, black!10] (-.5,-.5) grid (7.5,3.5);
  \draw [ebo corners=1] (0,0) rectangle ++(3,3) node [midway] {\footnotesize\texttt{rounded corners=1}};
  \draw [rounded corners=1cm] (4,0) rectangle ++(3,3) node [midway] {\footnotesize\texttt{rounded corners=1cm}};
  \begin{scope}[ebo unit=mm,blue]
    \draw [ebo corners=5] (0,0) ++(.25,.25) rectangle ++(3,3) node [midway] {\footnotesize\texttt{rounded corners=5}};
    \draw [rounded corners=5mm] (4,0) ++(.25,.25) rectangle ++(3,3) node [midway] {\footnotesize\texttt{rounded corners=5mm}};
  \end{scope}
  \begin{scope}[ebo unit=ex,green]
    \draw [ebo corners=8] (0,0) ++(-.25,-.25) rectangle ++(3,3) node [midway] {\footnotesize\texttt{rounded corners=8}};
    \draw [rounded corners=8ex] (4,0) ++(-.25,-.25) rectangle ++(3,3) node [midway] {\footnotesize\texttt{rounded corners=8ex}};
  \end{scope}
\end{tikzpicture}
\end{document}

ebo corners and rounded corners

cfr
  • 198,882