水平连接两个不同形状的锚点

水平连接两个不同形状的锚点

我定义了两个形状:myComponent1,其中包括两个锚点(PinAPinB),以及myComponent2,其中包括一个锚点(PinA)。我正在寻求有关如何使用水平线直接连接PinA从到从myComponent1的指导。下面,您将找到我的 LaTeX 代码以及相应的输出。最后,我已包含所需的结果。PinAmyComponent2

代码:

\documentclass{article}

\usepackage{circuitikz}

%% defining My Component 1
\pgfdeclareshape{myComponent1}{
    
    \anchor{center}{\pgfpointorigin}
    
    \savedanchor\PinA{\pgfpoint{60}{50}}
    \anchor{PinA}{\PinA}
    \savedanchor\PinB{\pgfpoint{60}{-50}}
    \anchor{PinB}{\PinB}
    
    \foregroundpath{
        
        \pgfpathrectanglecorners{\pgfpoint{-60}{-100}}{\pgfpoint{60}{100}}
        \pgfusepath{draw}
        
        \pgftext[right, at={\PinA}]{PIN A}
        \pgftext[right, at={\PinB}]{PIN B}
    }
}

%% defining My Component 2
\pgfdeclareshape{myComponent2}{
    
    \anchor{center}{\pgfpointorigin}
    
    \savedanchor\PinA{\pgfpoint{-60}{0}}
    \anchor{PinA}{\PinA}
    
    \foregroundpath{
        
        \pgfpathrectanglecorners{\pgfpoint{-60}{-100}}{\pgfpoint{60}{100}}
        \pgfusepath{draw}
        
        \pgftext[left, at={\PinA}]{PIN A}
    }
}

\begin{document}
    
    \begin{circuitikz}

        \draw (0,0) node[myComponent1, blue] (C1) {};
        \draw (8,5) node[myComponent2, red]  (C2) {};
        
        \draw (C1.PinA) -- (C2.PinA);
    
    \end{circuitikz}
    
\end{document}

输出:

在此处输入图片描述

期望的结果:

在此处输入图片描述

答案1

如果两个形状的锚点位于不同的垂直位置,则显然无法用水平线将它们连接起来。

您可以做的是绘制第一个形状,绘制一条水平线,然后使用锚点添加第二个形状:

 \draw (0,0) node[myComponent1, blue] (C1) {};
 \draw (C1.PinA) -- ++(3,0) node[myComponent2, red, anchor=PinA] (C2) {};

在此处输入图片描述

无论如何,这与没有什么特别的circuitikz,它只是简单的 TiZ... 完整的 MWE:

\documentclass{article}
\usepackage{tikz}

%% defining My Component 1
\pgfdeclareshape{myComponent1}{
    \anchor{center}{\pgfpointorigin}
    \savedanchor\PinA{\pgfpoint{60}{50}}
    \anchor{PinA}{\PinA}
    \savedanchor\PinB{\pgfpoint{60}{-50}}
    \anchor{PinB}{\PinB}
    \foregroundpath{
        \pgfpathrectanglecorners{\pgfpoint{-60}{-100}}{\pgfpoint{60}{100}}
        \pgfusepath{draw}
        \pgftext[right, at={\PinA}]{PIN A}
        \pgftext[right, at={\PinB}]{PIN B}
    }
}
%% defining My Component 2
\pgfdeclareshape{myComponent2}{
    \anchor{center}{\pgfpointorigin}
    \savedanchor\PinA{\pgfpoint{-60}{0}}
    \anchor{PinA}{\PinA}
    \foregroundpath{
        \pgfpathrectanglecorners{\pgfpoint{-60}{-100}}{\pgfpoint{60}{100}}
        \pgfusepath{draw}
        \pgftext[left, at={\PinA}]{PIN A}
    }
}

\begin{document}
\begin{tikzpicture}
    \draw (0,0) node[myComponent1, blue] (C1) {};
    \draw (C1.PinA) -- ++(3,0) node[myComponent2, red, anchor=PinA] (C2) {};
\end{tikzpicture}
\end{document}

相关内容