1

I am new to tikz and am trying to reproduce the following simple diagram

enter image description here

I did the following,

\usepackage{circuitikz}
\begin{tikzpicture}
    \node (p) at (0,0) {$p$};
    \node (p2) at (0,0.5) {$p$};
    \node (p3) at (2.5,0.25) {$\overline{p}$};
    \node[american nand port, draw] at ($(p) + (2.0,0.25)$) (NAND1) {};
            
    \draw (p) -- (NAND1.in 2);
    \draw (p2) -- (NAND1.in 1);
    \draw (NAND1.out 1) -- (p3);
\end{tikzpicture}

I get the following result enter image description here

The lines from the p's are not straight, I could tweak the nodes from like 0.52, -0.01 but that seems like a wrong approach. How can I make these elements with discrete distances ?

3
  • 1
    Welcome to TeX.SX! Next time, please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.
    – Rmano
    Feb 6, 2021 at 19:56
  • 1
    @Rmano I was unaware of that, thank you for letting me know !
    – hexaquark
    Feb 6, 2021 at 20:07
  • It is a lot easier to place the gate first and position the wires relative to the pins. You can use [anchor=in 1] to position the gate relative to pin 1 (for example), but only for one pin per gate. Feb 7, 2021 at 1:27

1 Answer 1

2

Basically, you can't. Sizes of the circuitikz components are built based on a standard size; you can tweak it to have, for example, 2-input ports at a given distance (if you do not rescale the TikZ coordinates), see here: Needing a dipchip of CircuiTikz with exact pin distance --- you will need to put them at 0.5 cm to have your example with straight lines.

BUT the best solution is using coordinates that are relative to the anchors:

\documentclass[border=10pt]{standalone}
\usepackage[siunitx, RPvoltages]{circuitikz}
\begin{document}
\begin{tikzpicture}
    \node[american nand port, draw] at (0,0) (NAND1) {};

    \draw (NAND1.in 2) -- ++(-0.5,0) coordinate(p);
    \draw (NAND1.in 1) -- ++(-0.5,0) coordinate(p2);
    \draw (NAND1.out) coordinate (p3);

    \node[left] at (p) {$p$};
    \node[left] at (p2) {$p$};
    \node[right] at (p3) {$\overline{p}$};
\end{tikzpicture}
\end{document}

enter image description here

Are you sure you do not want standard IEEE ports? If you add \ctikzset{logic ports=ieee} you have the option to change pin lengths, see Simple Logic gates with circuitikz - increase I/O line length

As an example, let's see how to make your example work with absolute lengths. If you look at the manual (pag. 119) you discover that the default height of the ports is 0.8 basic units. So if I make the basic unit 1.25cm, the port will be 1 cm tall, and the connections 0.5 cm apart.

\documentclass[border=10pt]{standalone}
\usepackage[siunitx, RPvoltages]{circuitikz}
\ctikzset{bipoles/length=1.25cm}
\begin{document}
\begin{tikzpicture}
    \node (p) at (0,0) {$p$};
    \node (p2) at (0,0.5) {$p$};
    \node (p3) at (2.5,0.25) {$\overline{p}$};
    \node[american nand port, draw] at ($(p) + (2.0,0.25)$) (NAND1) {};
            
    \draw (p) -- (NAND1.in 2);
    \draw (p2) -- (NAND1.in 1);
    \draw (NAND1.out) -- (p3);
\end{tikzpicture}
\end{document}

enter image description here

Still, this solution is not optimal. Rounding errors are prone to create problems (especially to the antialiasing routines of PDF viewers...)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .