[Tex/LaTex] Draw transmission line circuits

circuitikzcircuitstikz-pgf

This is an example of a transmission line circuit:

(Another one is available here). Transmission lines are conventionally drawn with two horizontal, parallel cylinders, with variable, adaptable length. I didn't find anything similar in circuitikz. In the manual (page 8), a single transmission line stub is provided, but it is a small, single cylinder with fixed length.

How to draw the above example circuit with circuitikz or tikz?

Best Answer

How about this? I edited the original version of the tline drawer to make the cylinder have length determined by the length of the line segment.

\documentclass{article}
\usepackage{circuitikz}
\usepackage{etoolbox}
\makeatletter

\pgfcircdeclarebipole{}
    {\ctikzvalof{bipoles/tline/height}}{tline}
    {\ctikzvalof{bipoles/tline/height}}
    {\ctikzvalof{bipoles/tline/width}}
{   
    %% First find distance from startpoint to endpoint
    \pgfpointdiff{\pgfpointanchor{\ctikzvalof{bipole/name}start}{center}}
                 {\pgfpointanchor{\ctikzvalof{bipole/name}end}{center}}
    \pgfmathparse{veclen(\the\pgf@x,\the\pgf@y)}
    %% The coordinate system has been changed so that the origin is at the midpoint and
    %% the line is along the x axis. So shift back by half the length of the line, and 
    %% make the cylinder of width roughly the length of the line, with a 40pt setback
    %% on each side.
    \pgftransformxshift{\pgfmathresult/2-30pt}
    \pgf@circ@res@left=\dimexpr-\pgfmathresult pt+40pt\relax
    %% Here is the original function, copied directly from the source of circuittikz, 
    %% down to next %%
    \pgf@circ@res@step=.2\pgf@circ@res@right % half x axis
    \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
    \pgfpathellipse{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@step}{0}}
                   {\pgfpoint{\pgf@circ@res@step}{0}}
                   {\pgfpoint{0}{-\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@step}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left+\pgf@circ@res@step}{\pgf@circ@res@up}}
    \pgfpatharc{-90}{90}{-\pgf@circ@res@step and -\pgf@circ@res@up}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@step}{\pgf@circ@res@down}}
    %% I have to fill the figure to block out the original line
    \pgfsetfillcolor{white}
    \pgfusepath{draw,fill}
    %% Redraw part of the line that gets blocked by the cylinder by mistake
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-2*\pgf@circ@res@step}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfusepath{draw}
}
\begin{document}
\begin{circuitikz}
\draw (0,0) to[TL] (10,0) to[TL] (14,4);
\end{circuitikz}
\end{document}