[Tex/LaTex] Circuitikz: How to place a box around a diode

circuitikz

I'm trying to create a simplified symbol for a TL431 which has a zener diode in the center and three pins, cathode, anode and ref.

What I tried so far is to make use of the box function of circuitikz. However, it won't let me place a box around a zener (nor a regular diode). I also tried to scale down the diode with /tikz/circuitikz/bipoles/length=0.5cm and use the box option, but still nothing:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[siunitx,fetbodydiode,smartlabels]{circuitikz}
\usetikzlibrary{positioning}
\begin{document}

\begin{figure}
\centering


\begin{circuitikz}[lbl/.style = {label={[label distance=4mm]above right:#1}}] % this line defines a new style to alter the distance of labels, mosfets due to diode and transformer label
        \draw
    (0,0) node[mixer,box,anchor=east] (m) {}
    to[/tikz/circuitikz/bipoles/length=0.5cm,Do,box,>,-o] ++(2.5,0)
    (m.west) node[inputarrow] {} to[short,-o]
    ++(-0.8,0)
    (m.south) node[inputarrow,rotate=90] {} --
    ++(0,-0.7) node[/tikz/circuitikz/bipoles/length=0.5cm,Do,box,anchor=north] {}
    ;
\end{circuitikz}



  \caption[Ersatzschaltbild]{Ersatzschaltbild}
  \label{fig:ersatzschaltbild}
\end{figure}
\end{document}

Apart from the box, as an alternative, can I just use a regular zener which is included in circuitikz and add a third ref pin to it? How can I achieve that?

Thanks 🙂

/EDIT here is my result so far. Feel free to use it. Thanks for all your help.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[siunitx,european,fetbodydiode,smartlabels]{circuitikz}
\usetikzlibrary{positioning}
\begin{document}


\begin{circuitikz}[lbl/.style = {label={[label distance=4mm]above right:#1}}] % this line defines a new style to alter the distance of labels, mosfets due to diode and transformer label

% Creating an smart objet 
\def\TL431(#1)#2{%#1: Position#2: Identifier.
    \begin{scope}[shift={(#1)}] % using to make coordinate objet.
        \draw 
        (0,0) coordinate (A) coordinate (A #2)  % set this coordinate as anode
        to [zzD*,-](0,2) coordinate (B) coordinate (K #2); % set this coordinate to kathode (zzD* is circuittikz object)
        \coordinate (C) at ($(A)!0.5!(B)$); % find the center point between A and B
        \coordinate (D) at ($(A)!1!90:(C)$); % find a point orthogonal. 
        \node at (C) [rectangle, minimum size=7mm,draw=black,thick] {}; % input rectangle
        \draw (C) -- +(D) coordinate (R #2);% draw the Vref pin and set tho coordinate Ref
        % Set the labels
        \draw (0,0.5) node[right] {\scriptsize A};
        \draw (0,1.5) node[right] {\scriptsize K};
        \draw (-1,0.8) node[right] {\scriptsize Ref};
        %\draw (.4,1) node[right] {\small D - #2}; % diode label identifier % for later use
        \draw (.4,1) node[right] {\small TL431}; % diode label identifier

    \end{scope}
}
% Creating an smart objet 
\def\Optocoupler(#1)#2{%#1: Position#2: Identifier.
    \begin{scope}[shift={(#1)}] % using to make coordinate objet.
        \draw 
        (0,0) coordinate (A) coordinate (Dr #2)  % set this coordinate as drain
        (0,2) coordinate (B) coordinate (K #2);

        \coordinate (C) at ($(A)!0.5!(B)$); % find the center point between A and B
        \coordinate[left=5mm of C] (Cl);
        \coordinate[left=5mm of A] (Al);
        \coordinate[left=5mm of B] (Bl);
        \coordinate[right=5mm of C] (Cr);
        \coordinate[right=5mm of A] (Ar);
        \coordinate[right=5mm of B] (Br);

        \draw (Bl) to [leDo] (Al);
        \draw (Cr) node[npn,photo,nobodydiode](npn){};
        \coordinate (D) at ($(A)!1!90:(C)$); % find a point orthogonal. 
        \node at (C) [rectangle, minimum width=2cm,minimum height=1cm,draw=black,thick] {}; % input rectangle
        \draw (npn.C) to (Br) to[short,-o] ++ (.75,0) node[right]{C}; 
        \draw (npn.E) to (Ar) to[short,-o] ++ (.75,0) node[right]{E};
        \draw (1,1) node[right] {\small IL213AT}; % diode label identifier

    \end{scope}
}

\ctikzset{bipoles/length=.8cm} % to avoid modify text sizes and separations.
% drawing first line input - R - Output
\draw (0,0) node [vcc](vcc){$U_{out}=\SI{24}{\volt}$};

% insert TL431 in position 2,-6 and identified as 1
\TL431(2,-6){1};
% conect first line and TL431 
% \draw (2,0) to [short,*-*] (K 1); % K 1 is the identified coordinate kathode % for later use
% Conect TL431 to ground
\draw (A 1) to (2,-7) node [rground]{} coordinate(ground); % A 1 is the identified coordinate of anode

% draw the close loop between Ref and K
\draw(R 1) --++ (-1,0) coordinate (ref);
%\draw[-] (ref) |- (K 1); % for later use
\draw (ref) to[short,*-*] ++ (0,1) coordinate(c1);
\draw (c1) to[R,l_=$R_{F2}$,v^<=$U_{F2}$] ++ (0,2) coordinate(V24);
\draw (ref) to[R,l=$R_{F1}$,v=$U_{F1}$] ++(0,-2) node[rground]{};
\draw (c1) to[C,label=$C_{F1}$] (K 1);
\draw (vcc) to[short,-*] (V24);

% for testing is inserted another TL431 identified as 2 % for later use
%\TL431(7,-6){2};
% you can connect both
%\draw [-, dashed] (K 1) -- (K 2);

% Optocoupler side

\Optocoupler(4,-4){2};
\draw (V24) to [R,label=$R_{Led}$] (Bl);
\draw (Al) to[short,-*] (K 1);

\end{circuitikz}

\end{document}

Best Answer

Whenever there is no element not included in some package, for example circuitikz, you always have the old comfiable brute force, you can define an object as if you were creating its schematic in some CAD program for circuits, you can name the pins so that later you can connect them using identifiers, here the code that I hope will be useful.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% By J. Leon V.  coded based on the BSD, MIT, Berware licences.
\documentclass{article}
\usepackage[utf8]{inputenc} % Input codification
\usepackage[active,tightpage,floats]{preview} % for previsualization in TikzEdt.
\usepackage[scaled]{uarial} % Arial like font
\usepackage[T1]{fontenc} % Allow to use 256 gliphs.
\usepackage{tikz} 
\usetikzlibrary{babel}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{1pt}%
\renewcommand*\familydefault{\sfdefault} % Serif fammily

\usetikzlibrary{arrows,positioning,backgrounds,shapes}
\usepackage[american]{circuitikz} 
\usetikzlibrary{calc,arrows} % to calculate coordinates.
\begin{document}

\begin{tikzpicture}[% Global configuration
    background rectangle/.style={%Background style
        rectangle, 
        rounded corners,
        shade,
        top color=black!3,
        bottom color=black!3!black!3,
        draw=black!40!black!60,dashed,
        },
    show background rectangle , % to activate or deactivate background
    scale=1
    ]

% Creating an smart objet 
 \def\TL431(#1)#2{%#1: Position#2: Identifier.
  \begin{scope}[shift={(#1)}] % using to make coordinate objet.
    \draw 
        (0,0) coordinate (A) coordinate (A #2)  %set this coordinate as anode
            to [sD*,-](0,2) coordinate (B) coordinate (K #2); % set this coordinate to kathode (sD* is circuittikz objet)
    \coordinate (C) at ($(A)!0.5!(B)$); % Find the center point between A and B
    \coordinate (D) at ($(A)!1!90:(C)$); % find a point orthogonal. 
    \node at (C) [rectangle, minimum size=7mm,draw=black,thick] {};%put the rectangle.
    \draw (C) -- +(D) coordinate (R #2);% draw the Vref pin and set tho coordinate Ref
    % Set the labels
    \draw (0,0.5) node[right] {\scriptsize A};
    \draw (0,1.5) node[right] {\scriptsize K};
    \draw (-.7,0.8) node[right] {\scriptsize R};
    \draw (.4,1) node[right] {\small D - #2}; % Diode label identifier

  \end{scope}
}

\ctikzset{bipoles/length=.8cm} % to navoid modify text sizes and separations.
 %Drawing first line input - R - Output
 \draw
    (0,0) node [anchor=east]{Input}
        to[R,o-*](2,0)
        to [short,-o] (3.5,0) node [anchor=west,-o]{Output} ;
% Insert TL431 in position 2,-3 and identified as 1
\TL431(2,-3){1};
% Conect first line and TL431 
\draw
    (2,0) to [short,-*] (K 1); % K 1 is the identified coordinate kathode
% Conect TL431 to ground
\draw (A 1) to (2,-4) node [ground]{};% A 1 is the identified coordinate of anode

%Draw the close loop between Ref and kathode
\draw[-] (R 1) |- (K 1);
%Draw the Vref 
\draw
    (R 1) to [short, -o] (1,-2.5)
        to [open,v=Vref] (1,-3.5)
        to [short, o-] (1,-4) node[ground]{};
% For testing is inserted another TL431 identified as 2.

\TL431(7,-3){2};
% you can conect both.
\draw [-, dashed] (K 1) -- (K 2);

\end{tikzpicture}
\end{document}

The following are obtained:

enter image description here