3

I am creating a circuit diagram using LaTeX and Circuitikz, but I'm having trouble aligning two LEDs vertically. I want both LEDs to be at the same x-position to ensure they are vertically aligned.

My Output:

In the output, the green and red LEDs are not vertically aligned as shown in the screenshot below:

enter image description here

My Desired Output:

I would like the green and red LEDs to be vertically aligned, as shown in the desired output below:

enter image description here

My Code:

\documentclass[border=0cm]{standalone}

\usepackage[emptydiode]{circuitikz} % For an empty diode symbol
\usetikzlibrary{ext.paths.ortho}


\pgfqkeys{/mm}{myLabel/.initial=DefaultLabel}

\pgfdeclareshape{ESPuC}{
    
    % define saved anchor
    % ----------------------------------------
    \anchor{center}{\pgfpointorigin}
    
    % define Connectors relative to the center
    % ----------------------------------------
    \savedanchor\myICpinA{\pgfpoint{-40}{91}}
    \savedanchor\myICpinB{\pgfpoint{-40}{78}}
    \savedanchor\myICpinC{\pgfpoint{-40}{65}}
    \savedanchor\myICpinD{\pgfpoint{-40}{52}}
    \savedanchor\myICpinE{\pgfpoint{-40}{39}}
    \savedanchor\myICpinF{\pgfpoint{-40}{26}}
    \savedanchor\myICpinG{\pgfpoint{-40}{13}}
    \savedanchor\myICpinH{\pgfpoint{-40}{0}}
    \savedanchor\myICpinI{\pgfpoint{-40}{-13}}
    \savedanchor\myICpinJ{\pgfpoint{-40}{-26}}
    \savedanchor\myICpinK{\pgfpoint{-40}{-39}}
    \savedanchor\myICpinL{\pgfpoint{-40}{-52}}
    \savedanchor\myICpinM{\pgfpoint{-40}{-65}}
    \savedanchor\myICpinN{\pgfpoint{-40}{-78}}
    \savedanchor\myICpinO{\pgfpoint{-40}{-91}}
    
    \savedanchor\myICpinAA{\pgfpoint{40}{91}}
    \savedanchor\myICpinBB{\pgfpoint{40}{78}}
    \savedanchor\myICpinCC{\pgfpoint{40}{65}}
    \savedanchor\myICpinDD{\pgfpoint{40}{52}}
    \savedanchor\myICpinEE{\pgfpoint{40}{39}}
    \savedanchor\myICpinFF{\pgfpoint{40}{26}}
    \savedanchor\myICpinGG{\pgfpoint{40}{13}}
    \savedanchor\myICpinHH{\pgfpoint{40}{0}}
    \savedanchor\myICpinII{\pgfpoint{40}{-13}}
    \savedanchor\myICpinJJ{\pgfpoint{40}{-26}}
    \savedanchor\myICpinKK{\pgfpoint{40}{-39}}
    \savedanchor\myICpinLL{\pgfpoint{40}{-52}}
    \savedanchor\myICpinMM{\pgfpoint{40}{-65}}
    \savedanchor\myICpinNN{\pgfpoint{40}{-78}}
    \savedanchor\myICpinOO{\pgfpoint{40}{-91}}
    
    \anchor{PinA}{\myICpinA}
    \anchor{PinB}{\myICpinB}
    \anchor{PinC}{\myICpinC}
    \anchor{PinD}{\myICpinD}
    \anchor{PinE}{\myICpinE}
    \anchor{PinF}{\myICpinF}
    \anchor{PinG}{\myICpinG}
    \anchor{PinH}{\myICpinH}
    \anchor{PinI}{\myICpinI}
    \anchor{PinJ}{\myICpinJ}
    \anchor{PinK}{\myICpinK}
    \anchor{PinL}{\myICpinL}
    \anchor{PinM}{\myICpinM}
    \anchor{PinN}{\myICpinN}
    \anchor{PinO}{\myICpinO}
    
    \anchor{PinAA}{\myICpinAA}
    \anchor{PinBB}{\myICpinBB}
    \anchor{PinCC}{\myICpinCC}
    \anchor{PinDD}{\myICpinDD}
    \anchor{PinEE}{\myICpinEE}
    \anchor{PinFF}{\myICpinFF}
    \anchor{PinGG}{\myICpinGG}
    \anchor{PinHH}{\myICpinHH}
    \anchor{PinII}{\myICpinII}
    \anchor{PinJJ}{\myICpinJJ}
    \anchor{PinKK}{\myICpinKK}
    \anchor{PinLL}{\myICpinLL}
    \anchor{PinMM}{\myICpinMM}
    \anchor{PinNN}{\myICpinNN}
    \anchor{PinOO}{\myICpinOO}
        
    \foregroundpath{
        
        \pgfpathrectanglecorners{\pgfpoint{-40}{-104}}{\pgfpoint{40}{104}}
        \pgfusepath{draw}
        
        \pgftext[left,  at={\myICpinA}]{ \texttt{A0}}
        \pgftext[left,  at={\myICpinB}]{ \texttt{G}}
        \pgftext[left,  at={\myICpinC}]{ \texttt{VV}}
        \pgftext[left,  at={\myICpinD}]{ \texttt{S3}}
        \pgftext[left,  at={\myICpinE}]{ \texttt{S2}}
        \pgftext[left,  at={\myICpinF}]{ \texttt{S1}}
        \pgftext[left,  at={\myICpinG}]{ \texttt{SC}}
        \pgftext[left,  at={\myICpinH}]{ \texttt{S0}}
        \pgftext[left,  at={\myICpinI}]{ \texttt{SK}}
        \pgftext[left,  at={\myICpinJ}]{ \texttt{G}}
        \pgftext[left,  at={\myICpinK}]{ \texttt{3V}}
        \pgftext[left,  at={\myICpinL}]{ \texttt{EN}}
        \pgftext[left,  at={\myICpinM}]{ \texttt{RST}}
        \pgftext[left,  at={\myICpinN}]{ \texttt{G}}
        \pgftext[left,  at={\myICpinO}]{ \texttt{VIN}}
        
        \pgftext[right,  at={\myICpinAA}]{\texttt{D0} }
        \pgftext[right,  at={\myICpinBB}]{\texttt{D1} }
        \pgftext[right,  at={\myICpinCC}]{\texttt{D2} }
        \pgftext[right,  at={\myICpinDD}]{\texttt{D3} }
        \pgftext[right,  at={\myICpinEE}]{\texttt{D4} }
        \pgftext[right,  at={\myICpinFF}]{\texttt{3V} }
        \pgftext[right,  at={\myICpinGG}]{\texttt{G} }
        \pgftext[right,  at={\myICpinHH}]{\texttt{D5} }
        \pgftext[right,  at={\myICpinII}]{\texttt{D6} }
        \pgftext[right,  at={\myICpinJJ}]{\texttt{D7} }
        \pgftext[right,  at={\myICpinKK}]{\texttt{D8} }
        \pgftext[right,  at={\myICpinLL}]{\texttt{RX} }
        \pgftext[right,  at={\myICpinMM}]{\texttt{TX} }
        \pgftext[right,  at={\myICpinNN}]{\texttt{G} }
        \pgftext[right,  at={\myICpinOO}]{\texttt{3V} }
        
        % my static label
        \pgftext[center, at={\pgfpoint{0}{109}}]{\small\textcolor{black}{\pgfkeysvalueof{/mm/myLabel}}}
    }
    
}


\begin{document}
    \ctikzset{bipoles/length=.8cm}
    \begin{circuitikz}
        \draw (0,0) node[ESPuC, /mm/myLabel=ESP8266] (esp) {};
        
        \draw[blue] (esp.PinNN) -- ++(6,0);
        \draw[red] (esp.PinOO) -- ++(6,0);
        
        
        \draw (esp.PinII) to [R, l=$330\Omega$] ++(2,0) to  [fill=red, led, l=LED] ++(2,0) 
        -- ++(0,-2) coordinate (kathode)
        -- (esp.PinNN -| kathode) node[ground, blue, circ]{};
        
        \draw (esp.PinCC) to [R, l=$330\Omega$] ++(2,0) to  [fill=green, led, l=LED] ++(3,0) 
        -- ++(0,-2) coordinate (kathode)
        -- (esp.PinNN -| kathode) node[ground, blue, circ]{};
        
    \end{circuitikz}
\end{document} 

1 Answer 1

7

That both diode be parallel, they should be drawn in the paths of the same lengths:

\documentclass[border=0cm]{standalone}
\usepackage[emptydiode]{circuitikz} % For an empty diode symbol

\pgfqkeys{/mm}{myLabel/.initial=DefaultLabel}

\pgfdeclareshape{ESPuC}{
    
    % define saved anchor
    % ----------------------------------------
    \anchor{center}{\pgfpointorigin}
    
    % define Connectors relative to the center
    % ----------------------------------------
    \savedanchor\myICpinA{\pgfpoint{-40}{91}}
    \savedanchor\myICpinB{\pgfpoint{-40}{78}}
    \savedanchor\myICpinC{\pgfpoint{-40}{65}}
    \savedanchor\myICpinD{\pgfpoint{-40}{52}}
    \savedanchor\myICpinE{\pgfpoint{-40}{39}}
    \savedanchor\myICpinF{\pgfpoint{-40}{26}}
    \savedanchor\myICpinG{\pgfpoint{-40}{13}}
    \savedanchor\myICpinH{\pgfpoint{-40}{0}}
    \savedanchor\myICpinI{\pgfpoint{-40}{-13}}
    \savedanchor\myICpinJ{\pgfpoint{-40}{-26}}
    \savedanchor\myICpinK{\pgfpoint{-40}{-39}}
    \savedanchor\myICpinL{\pgfpoint{-40}{-52}}
    \savedanchor\myICpinM{\pgfpoint{-40}{-65}}
    \savedanchor\myICpinN{\pgfpoint{-40}{-78}}
    \savedanchor\myICpinO{\pgfpoint{-40}{-91}}
    
    \savedanchor\myICpinAA{\pgfpoint{40}{91}}
    \savedanchor\myICpinBB{\pgfpoint{40}{78}}
    \savedanchor\myICpinCC{\pgfpoint{40}{65}}
    \savedanchor\myICpinDD{\pgfpoint{40}{52}}
    \savedanchor\myICpinEE{\pgfpoint{40}{39}}
    \savedanchor\myICpinFF{\pgfpoint{40}{26}}
    \savedanchor\myICpinGG{\pgfpoint{40}{13}}
    \savedanchor\myICpinHH{\pgfpoint{40}{0}}
    \savedanchor\myICpinII{\pgfpoint{40}{-13}}
    \savedanchor\myICpinJJ{\pgfpoint{40}{-26}}
    \savedanchor\myICpinKK{\pgfpoint{40}{-39}}
    \savedanchor\myICpinLL{\pgfpoint{40}{-52}}
    \savedanchor\myICpinMM{\pgfpoint{40}{-65}}
    \savedanchor\myICpinNN{\pgfpoint{40}{-78}}
    \savedanchor\myICpinOO{\pgfpoint{40}{-91}}
    
    \anchor{PinA}{\myICpinA}
    \anchor{PinB}{\myICpinB}
    \anchor{PinC}{\myICpinC}
    \anchor{PinD}{\myICpinD}
    \anchor{PinE}{\myICpinE}
    \anchor{PinF}{\myICpinF}
    \anchor{PinG}{\myICpinG}
    \anchor{PinH}{\myICpinH}
    \anchor{PinI}{\myICpinI}
    \anchor{PinJ}{\myICpinJ}
    \anchor{PinK}{\myICpinK}
    \anchor{PinL}{\myICpinL}
    \anchor{PinM}{\myICpinM}
    \anchor{PinN}{\myICpinN}
    \anchor{PinO}{\myICpinO}
    
    \anchor{PinAA}{\myICpinAA}
    \anchor{PinBB}{\myICpinBB}
    \anchor{PinCC}{\myICpinCC}
    \anchor{PinDD}{\myICpinDD}
    \anchor{PinEE}{\myICpinEE}
    \anchor{PinFF}{\myICpinFF}
    \anchor{PinGG}{\myICpinGG}
    \anchor{PinHH}{\myICpinHH}
    \anchor{PinII}{\myICpinII}
    \anchor{PinJJ}{\myICpinJJ}
    \anchor{PinKK}{\myICpinKK}
    \anchor{PinLL}{\myICpinLL}
    \anchor{PinMM}{\myICpinMM}
    \anchor{PinNN}{\myICpinNN}
    \anchor{PinOO}{\myICpinOO}
        
    \foregroundpath{
        
        \pgfpathrectanglecorners{\pgfpoint{-40}{-104}}{\pgfpoint{40}{104}}
        \pgfusepath{draw}
        
        \pgftext[left,  at={\myICpinA}]{ \texttt{A0}}
        \pgftext[left,  at={\myICpinB}]{ \texttt{G}}
        \pgftext[left,  at={\myICpinC}]{ \texttt{VV}}
        \pgftext[left,  at={\myICpinD}]{ \texttt{S3}}
        \pgftext[left,  at={\myICpinE}]{ \texttt{S2}}
        \pgftext[left,  at={\myICpinF}]{ \texttt{S1}}
        \pgftext[left,  at={\myICpinG}]{ \texttt{SC}}
        \pgftext[left,  at={\myICpinH}]{ \texttt{S0}}
        \pgftext[left,  at={\myICpinI}]{ \texttt{SK}}
        \pgftext[left,  at={\myICpinJ}]{ \texttt{G}}
        \pgftext[left,  at={\myICpinK}]{ \texttt{3V}}
        \pgftext[left,  at={\myICpinL}]{ \texttt{EN}}
        \pgftext[left,  at={\myICpinM}]{ \texttt{RST}}
        \pgftext[left,  at={\myICpinN}]{ \texttt{G}}
        \pgftext[left,  at={\myICpinO}]{ \texttt{VIN}}
        
        \pgftext[right,  at={\myICpinAA}]{\texttt{D0} }
        \pgftext[right,  at={\myICpinBB}]{\texttt{D1} }
        \pgftext[right,  at={\myICpinCC}]{\texttt{D2} }
        \pgftext[right,  at={\myICpinDD}]{\texttt{D3} }
        \pgftext[right,  at={\myICpinEE}]{\texttt{D4} }
        \pgftext[right,  at={\myICpinFF}]{\texttt{3V} }
        \pgftext[right,  at={\myICpinGG}]{\texttt{G} }
        \pgftext[right,  at={\myICpinHH}]{\texttt{D5} }
        \pgftext[right,  at={\myICpinII}]{\texttt{D6} }
        \pgftext[right,  at={\myICpinJJ}]{\texttt{D7} }
        \pgftext[right,  at={\myICpinKK}]{\texttt{D8} }
        \pgftext[right,  at={\myICpinLL}]{\texttt{RX} }
        \pgftext[right,  at={\myICpinMM}]{\texttt{TX} }
        \pgftext[right,  at={\myICpinNN}]{\texttt{G} }
        \pgftext[right,  at={\myICpinOO}]{\texttt{3V} }
        
        % my static label
        \pgftext[center, at={\pgfpoint{0}{109}}]{\small\textcolor{black}{\pgfkeysvalueof{/mm/myLabel}}}
    }    
}

\begin{document}
    \ctikzset{bipoles/length=.8cm}
    \begin{circuitikz}
        \draw (0,0) node[ESPuC, /mm/myLabel=ESP8266] (esp) {};
        
        \draw[blue] (esp.PinNN) -- ++(6,0);
        \draw[red] (esp.PinOO) -- ++(6,0);
        
        
        \draw (esp.PinII) to [R, l=$330\Omega$] ++(2,0) to  [fill=red, led, l=LED] ++(2,0)
        -- ++(0,-2) coordinate (kathode)
        -- (esp.PinNN -| kathode) node[ground, blue, circ]{};
        
        \draw (esp.PinCC) to [R, l=$330\Omega$] ++(2,0) to  [fill=green, led, l=LED] ++(2,0)    % <--- 
        -- ++(1,0)  coordinate (kathode)                                                        % <---
        -- (esp.PinNN -| kathode) node[ground, blue, circ]{};
    \end{circuitikz}
\end{document} 

Edit:
Ups, I forgot to upload image of sheme ... Now added:

enter image description here

I wonder if circuitikz doesn't offer shorter way to define Integrated circuits shapes.

Addendum: Off-topic.
In original answer I wonder if exist shorter/simpler way to draw your sheme. With kind help of @rmano (circuitikz package coauthor; thank you very much!) below I wrote MWE with a suggestion, how can you write code for your sheme much more efficiently:

\documentclass[border=3mm]{standalone}
\usepackage[siunitx]{circuitikz} 


\begin{document}
    \begin{circuitikz}
\ctikzset{bipoles/length=.8cm}
\tikzset{ESP8266/.style={muxdemux, 
                         muxdemux def={Lh=15, NL=15, Rh=15, NR=15, w=4, NT=0, NB=0}, 
                         muxdemux label={L1=A0, L2=G,  L3=VV, L4=S3, L5=S2, L6=S1, L7=SC, L8=S0, L9=SK, L10=G, L11=3V, L12=EN, L13=RST, L14=G, L15=VIN, 
                                         R1=D0, R2=D1, R3=D2, R4=D3, R5=D4, R6=3V, R7=G,  R8=D5, R9=D6, R10=D7, R11=D8, R12=RX, R13=TX, R14=G, R15=3V, N=ESP8266}, 
                         }% end of style definition
        }% end of tikzset    
\node[ESP8266]  (esp) {};
\draw[blue]     (esp.rpin 14) -- ++ (6,0);
\draw[red]      (esp.rpin 15) -- ++ (6,0);

\draw           (esp.rpin 3)    to [R=330<\ohm>]            ++ (2,0) 
                                to [led=LED, fill=green]    ++ (2,0)
                                -- ++ (1,0)                             coordinate (kathode)
                                to [short, -*] (esp.rpin 14 -| kathode)
                (esp.rpin 9)    to [R=330<\ohm>]            ++ (2,0)
                                to [led=LED, fill=red]      ++ (2,0)    coordinate (kathode) 
                                to [short, -*] (esp.rpin 14 -| kathode)
                                ;
    \end{circuitikz}
\end{document} 

which produce very similar (and to my opinion more correct) result as your code:

enter image description here

6
  • 1
    yes, you can use the muxdemux shape with custom labels.
    – Rmano
    Commented Aug 15 at 11:48
  • @Rmano, you are right! Since I'm on vacation I was to lazy to check the package documentation ... 😉
    – Zarko
    Commented Aug 15 at 12:27
  • This is it (also on vacation, but ...): ` \tikzset{ESP8266/.style={muxdemux, muxdemux def={Lh=15, NL=15, Rh=15, NR=15, w=4, NT=0, NB=0}, muxdemux label={ L1=A0, L2=G, L3=VV, L4=S3, L5=S2, L6=S1, L7=SC, L8=S0, L9=SK, L10=G, L11=3V, L12=EN, L13=RST, L14=G, L15=VIN, R1=D0, R2=D1, R3=D2, R4=D3, R5=D4, R6=3V, R7=G, R8=D5, R9=D6, R10=D7, R11=D8, R12=RX, R13=TX, R14=G, R15=3V, N=ESP8266 }, }}`
    – Rmano
    Commented Aug 15 at 13:27
  • @Rmano, thank you very much! I will give a shot later ... now I'm middle of preparation fo a BBQ for my family (it is planned to last to late evening when is not so hot anymore).
    – Zarko
    Commented Aug 15 at 15:15
  • 1
    @Rmano, I succeed to wrote addendum to my answer with your proposal how to write a code for integrated circuit. Thank you very much!
    – Zarko
    Commented Aug 16 at 7:38

You must log in to answer this question.

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