14

I am trying to set up a small TikZ library or package with pics I can reuse.

Thus, I create a file called "tikzlibraryBES.code.tex" with the following content:

\tikzset{
   % House
   pics/house/.style args={#1/#2/#3}{
   code={
      % Define house parameters
      \newcommand\wallheight{#1}  % 0.65
      \newcommand\roofoverhang{#2}  % 0.15
      \newcommand\roofangle{#3}  % 35

      % Calculate some dependent sizes
      \pgfmathsetmacro\lengthroof{0.5/cos(\roofangle)+\roofoverhang}

      % draw profile of house
      \draw[line width=1pt] (-0.5,\wallheight) -- (-0.5,0) --  (0.5,0) -- (0.5,\wallheight) -- ++(-\roofangle:\roofoverhang) -- ++(180-\roofangle:\lengthroof) -- ++(180+\roofangle:\lengthroof) -- cycle;
    }},
}

I have another file where I want to use the library:

\documentclass[varwidth=false, border=2pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{arrows,positioning}

% Load tikz library in file "tikzlibraryBES.code.tex"
\usetikzlibrary{BES}

\begin{document}
\begin{tikzpicture}

\path (+1.5,-0.85) pic[scale=1.0] {house=0.65/0.15/35};

\end{tikzpicture}
\end{document}

This works fine so far, however, I would like to have the option to create the house shape with default values by using the following command:

\path (+1.5,-0.85) pic[scale=1.0] {house};

How can I achieve this: If no arguments are provided, the some default values are used?

0

1 Answer 1

19

Simply add a .default key at the end of the \tikzset call:

\tikzset{
  % House
  pics/house/.style args={#1/#2/#3}{
    code={ Code of the pic }
  },
  pics/house/.default=0.65/0.15/35
}
0

You must log in to answer this question.

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