## 编译环境 操作系统 * [X] Windows 7/8/10 * [ ] macOS * [ ] Linux `若需勾选,请把[ ]改成[x]` Tex发行版 * [X] TexLive `年份` * [ ] MikTeX `版本号` * [ ] CTeX `若需勾选,请把[ ]改成[x]` ## 我的问题 我准备自己做一个电路元件。具体说是一个电缆,circuitikz里有一个transmission line,但是没有地线我想做一个元件,现在是半成品。如果做成四端元件,画出node再连线,是可以的。但我想知道怎么在path上画node,node怎么盖住path。 \documentclass{article} \pagestyle{empty} \usepackage{circuitikz} \usepackage{xeCJK} \usepackage{graphicx} \usepackage{xcolor} \usepackage[T1]{fontenc} \usepackage{calc} \usepackage[paperwidth=10.5cm, paperheight=12.5cm,margin=1cm ]{geometry} \definecolor{XJBlue}{RGB}{0, 78, 151} \definecolor{XJRed}{RGB}{200, 22, 30} \definecolor{XJGray}{RGB}{220, 220, 221} \pgfdeclareshape{cable} { \anchor{center}{\pgfpointorigin} %中心点 \anchor{text} % {\pgfpoint{-0.5\wd\pgfnodeparttextbox}{-0.5\ht\pgfnodeparttextbox}} \savedanchor\in1{\pgfpoint{-1cm}{0cm}} % 入端信号/高压 \anchor{A1}{\in1} \savedanchor\in0{\pgfpoint{-1cm}{-0.5cm}} % 入端地 \anchor{A0}{\in0} \savedanchor\out1{\pgfpoint{1cm}{0cm}} % 出端信号/高压 \anchor{B1}{\out1} \savedanchor\out0{\pgfpoint{1cm}{-0.5cm}} % 出端地 \anchor{B0}{\out0} \foregroundpath{ % 图形在此输入 \pgfsetlinewidth{0.02cm} \begin{pgfscope} \pgfpathmoveto{\pgfpoint{1cm}{-0.22cm}} \pgfpathlineto{\pgfpoint{0.45cm}{-0.22cm}} \pgfpathlineto{\pgfpoint{0.45cm}{0.22cm}} \pgfpathlineto{\pgfpoint{1cm}{0.22cm}} \pgfusepath{clip} \pgfpathellipse{\pgfpoint{0.45cm}{0cm}} {\pgfpoint{0cm}{0.2cm}} {\pgfpoint{0.1cm}{0cm}} \pgfusepath{stroke} \end{pgfscope} \pgfpathmoveto{\pgfpoint{0.45cm}{-0.2cm}} \pgfpathlineto{\pgfpoint{-0.45cm}{-0.2cm}} \pgfpathmoveto{\pgfpoint{-0.45cm}{0.2cm}} \pgfpathlineto{\pgfpoint{0.45cm}{0.2cm}} \pgfusepath{stroke} \pgfpathellipse{\pgfpoint{-0.45cm}{0cm}} {\pgfpoint{0cm}{0.2cm}} {\pgfpoint{0.1cm}{0cm}} \pgfusepath{stroke} } } \begin{document} \begin{center} \begin{circuitikz} %\draw (0,0) to [transmission line] ++(2,0) coordinate(sw1) to [short, -*] ++(4,0); \draw (0,0) to node[cable,]{111} ++(2,0); \end{circuitikz} \end{center} \end{document}

3 回答3

0
\documentclass{article} \pagestyle{empty} \usepackage{circuitikz} \usepackage{xeCJK} \usepackage{graphicx} \usepackage{xcolor} \usepackage[T1]{fontenc} \usepackage{calc} \usepackage[paperwidth=10.5cm, paperheight=12.5cm,margin=1cm ]{geometry} \definecolor{XJBlue}{RGB}{0, 78, 151} \definecolor{XJRed}{RGB}{200, 22, 30} \definecolor{XJGray}{RGB}{220, 220, 221} \pgfdeclareshape{cable} %定义一个四端的电缆元件 { \anchor{center}{\pgfpointorigin} %中心点 \anchor{text} % {\pgfpoint{-0.5\wd\pgfnodeparttextbox}{-0.5\ht\pgfnodeparttextbox}} \savedanchor\AA{\pgfpoint{-0.75cm}{0cm}} % 入端信号/高压 \anchor{inA}{\AA} \savedanchor\AB{\pgfpoint{-0.45cm}{-0.2cm}} % 入端地 \anchor{inB}{\AB} \savedanchor\BA{\pgfpoint{0.75cm}{0cm}} % 出端信号/高压 \anchor{outA}{\BA} \savedanchor\BB{\pgfpoint{0.45cm}{-0.2cm}} % 出端地 \anchor{outB}{\BB} \foregroundpath{ % 图形在此输入 \pgfsetlinewidth{0.015cm} \begin{pgfscope} \pgfpathmoveto{\pgfpoint{0.6cm}{-0.22cm}} \pgfpathlineto{\pgfpoint{0.45cm}{-0.22cm}} \pgfpathlineto{\pgfpoint{0.45cm}{0.22cm}} \pgfpathlineto{\pgfpoint{0.6cm}{0.22cm}} \pgfusepath{clip} \pgfpathellipse{\pgfpoint{0.45cm}{0cm}} {\pgfpoint{0cm}{0.2cm}} {\pgfpoint{0.1cm}{0cm}} \pgfusepath{stroke} \end{pgfscope} \pgfpathmoveto{\pgfpoint{0.45cm}{-0.2cm}} \pgfpathlineto{\pgfpoint{-0.45cm}{-0.2cm}} \pgfpathmoveto{\pgfpoint{-0.45cm}{0.2cm}} \pgfpathlineto{\pgfpoint{0.45cm}{0.2cm}} \pgfpathmoveto{\pgfpoint{-0.75cm}{0cm}} \pgfpathlineto{\pgfpoint{-0.45cm}{0cm}} \pgfpathmoveto{\pgfpoint{0.55cm}{0cm}} \pgfpathlineto{\pgfpoint{0.75cm}{0cm}} \pgfusepath{stroke} \pgfpathellipse{\pgfpoint{-0.45cm}{0cm}} {\pgfpoint{0cm}{0.2cm}} {\pgfpoint{0.1cm}{0cm}} \pgfusepath{stroke} } } \begin{document} \begin{center} \begin{circuitikz} %\draw (0,0) to [transmission line] ++(2,0) coordinate(sw1) to [short, -*] ++(4,0); \node[cable] (A) at (0,0) {111} ; \draw (A.inA) --++(-2,0); \draw (A.inB) --++(-1,-1); \draw (A.outA) --++(2,0); \draw (A.outB) --++(-1,-1); \end{circuitikz} \end{center} \end{document}
0
看看如何用代码块功能 [https://wenda.latexstudio.net/q-1541.html](https://wenda.latexstudio.net/q-1541.html "https://wenda.latexstudio.net/q-1541.html")
0
通过自定义to path给你实现了一个,用pic也行,没必要自定义一个node shape ```tex \documentclass[tikz, border=1cm]{standalone} \usetikzlibrary{shapes.geometric} \usetikzlibrary{calc} \tikzset{ myellipse/.style args={#1 and #2}{ draw, shape=ellipse, minimum width=#1, minimum height=#2, }, cable pos/.store in=\cablepos, cable pos=.5, cable width/.store in=\cablewd, cable width=2cm, cable x radius/.store in=\cablex, cable x radius=.1cm, cable y radius/.store in=\cabley, cable y radius=.4cm, cable text/.store in=\cabletext, cable text=, cable node style/.store in=\cablesty, cable node style=, cable/.style={to path={ let \p1 = (\tikztostart), \p2 = (\tikztotarget) in let \n1 = {\x2 - \x1}, \n2 = {\y2 - \y1} in \pgfextra{\pgfmathsetmacro{\diffx}{\n1 / 1cm}} \pgfextra{\pgfmathsetmacro{\diffy}{\n2 / 1cm}} let \n{sqrt} = {sqrt((\diffx)^2 + (\diffy)^2)} in let \n{sign} = {\diffy > 0 ? 1 : (\diffy < 0 ? -1 : (\diffx > 0 ? 1 : -1))} in let \n{ang} = {\n{sign} * acos(\diffx / \n{sqrt})} in let \p{center} = ($(\p1)!\cablepos!(\p2)$) in let \p{left} = ($(\p{center}) - (\n{ang}:{.5*\cablewd})$) in let \p{right} = ($(\p{center}) + (\n{ang}:{.5*\cablewd})$) in let \p{upperleft} = ($(\p{left}) + ({\n{ang} + 90}:\cabley)$) in let \p{upperright} = ($(\p{right}) + ({\n{ang} + 90}:\cabley)$) in let \p{lowerleft} = ($(\p{left}) + ({\n{ang} - 90}:\cabley)$) in let \p{lowerright} = ($(\p{right}) + ({\n{ang} - 90}:\cabley)$) in -- (\p{left}) (\p{center}) node[rotate=\n{ang}, \cablesty] {\cabletext} (\p{upperleft}) -- (\p{upperright}) (\p{lowerleft}) -- (\p{lowerright}) {[rotate around={\n{ang}:(\p{left})}] (\p{left}) ++ (-90:\cabley) arc[ x radius=\cablex, y radius=\cabley, start angle=-90, end angle=270, ] } {[rotate around={\n{ang}:(\p{right})}] (\p{right}) ++ (-90:\cabley) arc[ x radius=\cablex, y radius=\cabley, start angle=-90, end angle=90, ] } ($(\p{right}) + (\n{ang}:\cablex)$) -- (\p2) \tikztonodes }} } \begin{document} \begin{tikzpicture} \foreach \x/\y/\z in {0/.3/2, 45/.4/2.5, 90/.5/3, 135/.6/3.5, 180/.7/4} { \typeout{aaa \x, \y, \z} \edef\a{\x} \edef\b{\y} \edef\c{\z} \draw[->] (0, 0) to[ cable, cable pos=\b, cable width=\c cm, cable text=cable, ] (\a:8cm); } \end{tikzpicture} \end{document} ``` ![](https://wenda.latexstudio.net/data/attach/200601/pFWKtf7R.png)

你的回答

请登录后回答

你的回答将会帮助更多人,请务必认真回答问题。