2

Here is what I have right now:

\documentclass[12pt]{article}
\usepackage{siunitx}
\usepackage{amsmath}
\usepackage[margin=1in]{geometry}
\usepackage[american,siunitx]{circuitikz}
\usepackage{tikz}
%\pgfplotsset{compat=1.18}
\usetikzlibrary{shapes,arrows,automata, positioning}
\usetikzlibrary{decorations.markings}
\tikzset{positionarrow/.style n args={2}{
        postaction = decorate,
        decoration={markings,
            mark= at position #1 with {\arrow{#2}} ,
        },
        postaction={decorate}
    }
}
\begin{document}
    \begin{center}
        \begin{center}
            \begin{circuitikz}
                \draw [blue](0,5) circle[radius=1.5 pt];
                \draw[blue, positionarrow={0.5}{Stealth[inset=0pt]}](0,5) to (3,5);
                \draw [blue](3,5) circle[radius=1.5 pt];
                \draw(0,4) to[short, i>^=$\hphantom{a}$, o-o](3,4);
                \draw [blue](0,3) circle[radius=1.5 pt];
                \draw[blue, positionarrow={0.5}{Stealth[inset=0pt]}](0,3) to (3,3);
                \draw [blue](3,3) circle[radius=1.5 pt];
                \draw(0,3) to[short, i>^=$\hphantom{a}$, o-o](3,3);
            \end{circuitikz}
        \end{center}
    \end{center}
\end{document}

Output:

enter image description here

I seemed to manage to get the circle radius to match that for ocirc (as shown in the bottom figure, the black ocirc with its default radius perfectly "covers up" the blue). Let me know if there's a better way of doing so.

From there, I would like to get some desired outputs:

  1. I would like to have the line in tikz code to start from the edge of the circle and end at the other edge of the circle, like how the wires in circuitikz start and end from the ocirc terminals, instead of starting and ending inside the circles.
  2. I realized that the arrow shape in tikz is not exactly the same as that in circuitikz (in reality, from my understanding, it is flowarrow that is defined as a node, not a specific arrow shape). Is there a way to get a tikz arrow shape that looks the same as that in circuitikz? If not, that's fine.
  3. I realized the arrow in tikz that is positioned half-way (0.5) is not necessarily half-way as is the arrow for circuitikz. Is there a way for one to get the arrow in tikz to match up the position of that in circuitikz?

This is a follow up from this, as I want to utilize curved lines (or directional edges in the graph, in other words) in addition with features from circuitikz, which does not use curved lines for wires.

Superman
  • 1,615

2 Answers2

4

This is a possible mixed solution (see also my answer to your previous question). Basically:

  1. for the circles, use the shape provided by circuitikz (ocirc), which has the correct border anchors.

  2. If you use it and use the node name instead of the coordinate, the lines will start from the correct borders.

  3. Arrows are not really arrows in circuitikz; they are the currarrow shape (see section 4.11 in the current manual). So you need to use the trick shown here and add a bit of tweaking on the position if you really want the same position.

\documentclass[12pt]{article}
\usepackage{siunitx}
\usepackage{amsmath}
\usepackage[margin=1in]{geometry}
\usepackage[american,siunitx]{circuitikz}
\usepackage{tikz}
%\pgfplotsset{compat=1.18}
\usetikzlibrary{shapes,arrows,automata, positioning}
\usetikzlibrary{decorations.markings}
% get the circuitikz arrow size, define a tip https://tex.stackexchange.com/a/549354/38080
\makeatletter
    \newdimen\ctikzAL\newdimen\ctikzAW
    \pgfmathsetlength{\ctikzAL}{ 1.7 * \pgf@circ@Rlen / \ctikzvalof{current arrow scale} + 2*\pgflinewidth}
    \pgfmathsetlength{\ctikzAW}{ 1.6 * \pgf@circ@Rlen / \ctikzvalof{current arrow scale} + 2*\pgflinewidth}
    \tikzset{c>/.tip={Triangle[length=\the\ctikzAL, width=\the\ctikzAW]}}
\makeatother
% See https://tex.stackexchange.com/a/39282/38080
\usetikzlibrary{decorations.markings}
\tikzset{->-/.style={decoration={
  markings,
  % circuitikz arrows are not arrows, they are shapes centered in the path.
  % the 0.525 simulates the same position, if needed; adjust it
  mark=at position 0.525 with {\arrow{c>}}},postaction={decorate}}}
\begin{document}
    \begin{center}
            \begin{circuitikz}
                \draw [blue](0,5) node[ocirc](A){} (3, 5) node[ocirc](B){};
                \draw [blue, ->-](A) -- (B);
                \draw(0,4) to[short, i>^=$\hphantom{a}$, o-o](3,4);
                \draw [blue](0,3) node[ocirc](C){} (3,3) node[ocirc](D){};
                \draw [blue, ->-](C) to (D);
                \draw(0,3) to[short, i>^=$\hphantom{a}$, o-o](3,3);
            \end{circuitikz}
    \end{center}
\end{document}

enter image description here

Rmano
  • 40,848
  • 3
  • 64
  • 125
  • Nice answer (+1). But I guess that one center environment is sufficient. It not need to be two nested in each other. – Zarko Nov 25 '23 at 12:51
  • 1
    Oh, yes. You are (very) right. I did not notice it ;-). Edited out. – Rmano Nov 25 '23 at 15:34
  • Hi Rmano, thank you for your explanation. Might if you elaborate more on borders and border anchors? Like, might if you depict what you mean by illustration via TikZ or CircuiTikZ? – Superman Nov 25 '23 at 17:40
  • The basic documentation is here: https://tikz.dev/tikz-shapes#sec-17.11; you can also look at https://tex.stackexchange.com/questions/199822/understanding-tikz-border-anchor . – Rmano Nov 25 '23 at 18:58
3

If I correctly understood you, then you looking for the the following:

\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                decorations.markings}
\tikzset{decoration={markings,
                     mark=at position 0.5 with {\arrow{Triangle}} ,
                    },
        }

\begin{document} \begin{tikzpicture} \draw[{Circle[open]}-{Circle[open]}, postaction={decorate}] (0,0) -- (3,0); \draw[red] (0,-0.2) -- (3,-0.2); \end{tikzpicture} \end{document}

enter image description here

Zarko
  • 296,517