1

I'm trying to define a new annotation for tikz circuit library which surrounds a shape with a circle of max(minimum width, minimum height).

updated with new information from Qrrbrbirlbel's comments, here's a semi-working example:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{circuits.ee.IEC}

\begin{document}
\tikzset
{
    circuit declare annotation={encapsulated}{\n1}
    {
        [shift=(\tikzlastnode.center)]
        let
            \n1={max(\pgfkeysvalueof{/pgf/minimum width},\pgfkeysvalueof{/pgf/minimum height})*\tikzcircuitssizeunit}
        in
            (0, 0) edge[to path={circle[radius={\n1}]}] ()
    }
}

\begin{tikzpicture}[circuit ee IEC]
    \draw (0, 0) to [resistor={encapsulated={info={$R_1$}}}] ++(right:3) to [diode={encapsulated={info={$D_1$}}}] ++(right:3);
\end{tikzpicture}
\end{document}

This is almost what I want, as the circle around the diode is correct. However, it doesn't surround the resistor correctly.

enter image description here

Instead, what I want looks like this:

enter image description here

I was able to achieve this by modifying the draw command as below, but I want this adjustment to be made without having to manually specify the minimum width each time.

\draw (0, 0) to [resistor={encapsulated={info={$R_1$}}}, minimum width=2] ++(right:2) to [diode={encapsulated={info={$D_1$}}}] ++(right:2);
  • You can't access the circuit symbol size key because it is a style and does not have any sub-keys. The keys can actually accessed by \pgfkeysvalueof{/pgf/minimum width}. But I'm not sure this is what you need in your context. Can you show a minimal working example? – Qrrbrbirlbel Jun 26 '13 at 6:26
  • thanks for that info, I updated with a semi-working example, a screenshot of the output, and a screenshot of the intended output using extra boiler-plate code I want to get rid of. – helloworld922 Jun 26 '13 at 7:17
  • Sadly, this is not how it works. The keys are only set correctly during the drawing of the nodes, after that you cannot rely on their values. If worst comes to worst the values are in no relation to the nodes as they may not even get used to calculate the node’s dimension. Let me propose two solutions … – Qrrbrbirlbel Jun 26 '13 at 15:21
2

In short: you cannot rely on the values of /pgf/minimum width and /pgf/minimum height because they may not be in any relation to the \tikzlastnode node.

My first solution which is more along the lines of your idea uses also calc’s let … in construct to find the actual radius (if you cannot rely on the north east anchor you can use others and then perform a max on all values). But somehow, the label distance is not used as one may expect. (The second argument of circuit declare annotation cannot use \n{@aux@ne}, we can work around that by just using the option [label distance=\n{@aux@ne}] again.)

The second annotation encapsulated* uses a circulare node with the through library to place a node. The #1 refer to the options used with encapsulated* (i.e. the infolabel) and is placed in my opinion as one would have expected.

Code

\documentclass[tikz,convert=false]{standalone}
\usetikzlibrary{circuits.ee.IEC,through}
\tikzset{
  circuit declare annotation={encapsulated}{0pt}{
    let
      \p{@aux@ne}=($(\tikzlastnode.north east)-(\tikzlastnode.center)$),
      \n{@aux@ne}={veclen(\x{@aux@ne},\y{@aux@ne})}
    in [label distance=\n{@aux@ne}]
      (\tikzlastnode.center) edge[to path={circle[radius={\n{@aux@ne}}]}] ()
  }
}
\tikzset{
  circuit declare annotation={encapsulated*}{0pt}{
     node[draw,circle through=(\tikzlastnode.north east),#1] at (\tikzlastnode.center) {}
  }
}
\begin{document}
\tikz[circuit ee IEC]
  \draw (0, 0) to [resistor={encapsulated={info={$R_1$}}}] ++(right:3) to [diode={encapsulated={info={$D_1$}}}] ++(right:3);

\tikz[circuit ee IEC]
  \draw (0, 0) to [resistor={encapsulated*={info={$R_1$}}}] ++(right:3) to [diode={encapsulated*={info={$D_1$}}}] ++(right:3);
\end{document}

Output

enter image description here

enter image description here

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.