1

I know that I can connect the points (0,0) and (1,1) using a horizontal then a vertical line using

\draw (0,0) -| (1,1);

Is there any behavior that allows one to do this using the to command?

\draw (0,0) to[-|] (1,1); % Doesn't work

For context, I'm trying to do this using CircuiTikz, and I want to use some of the other options that CircuitTikz adds to the to command.

Rmano
  • 40,848
  • 3
  • 64
  • 125

2 Answers2

3

It's possible to define your own to paths, see for example the final example of chapter 5 in the TikZ manual, the tutorial on "Diagrams as simple graphs". Section 14.13 The To Path Operation has the general documentation for this, I think.

No idea how this interacts with circuitikz stuff.

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[hv/.style={to path={-| (\tikztotarget) \tikztonodes}}]
\draw (0,0) to[hv] node [below] {foo} (1,1) ;
\end{tikzpicture}
\end{document}
Torbjørn T.
  • 206,688
1

No, the to[] path command has no such an option (I am sure there is somewhere an answer adding a to-path implementing such a thing, but I can't find it... "to" isn't exactly a search-friendly word — but anyway, it's not implemented in circuitikz, so the point is moot).

You gave little details, but if you want to add poles to the line, you can use the trick that when using -| or |-, the kink is at position 0.5:

\documentclass[border=10pt]{standalone}
\usepackage{circuitikz}
\begin{document}

\begin{tikzpicture}[american] \draw (0,0) -| node[pos=0.5, ocirc]{} (2,1);% really pos=0.5 is the default... \end{tikzpicture}

\end{document}

perpendicular path with a node in the angle

Remember that "open" poles are filled with white at the end of the path construction, so if you want to connect other elements to it using another path, you have to use the node name so that border anchors are engaged, not the bare coordinate (see the problem with the inductance!)

\documentclass[border=10pt]{standalone}
\usepackage{circuitikz}
\begin{document}

\begin{tikzpicture}[american] \draw (0,0) -| nodepos=0.5, ocirc{} (2,1); \draw (mynode) to[R] (0,1); \draw (0,0 -| 2,1) to[L] ++(2,0); \end{tikzpicture}

\end{document}

Using the node name and border anchors

Rmano
  • 40,848
  • 3
  • 64
  • 125