TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to typeset things that look like

enter image description here

I'm already aware of

  • Q-circuit, which has nice custom macros for this purpose, but is based on the relatively slow and clunky XyPic
  • TikZ, which I can use to manually set things up (that's how the picture I've hotlinked was drawn)

Are there any other alternatives I should know about?

share|improve this question
Quantum circuits are written in a similar way to sheet music. It'd be interesting if LilyPond could be adapted/abused to suit this purpose. – qubyte Feb 12 '12 at 11:35
up vote 8 down vote accepted

Apparently Nielsen and Chuang used qasm2circ to produce the figures in Quantum Computation and Quantum Information.

share|improve this answer
qasm2circ is also based on xypic, apparently. So it suffers from the same criticisms that the OP gave for qcircuit. – Seamus Jan 27 '11 at 15:02
OP's primary objection to XyPic was speed, which matters if you're using it every time you build your document (which is the standard workflow for Q-circuit). The workflow for qasm2circ is to build the quantum circuit diagrams beforehand and then use \includegraphics, which offsets the slowness of XyPic (and is a better workflow for preparing documents for publication). And regardless of the OP's objections to XyPic, the fact that qasm2circ was used to produce the quantum circuit diagrams for the book on quantum computation makes it an important alternative to be aware of. – las3rjock Jan 27 '11 at 19:41
I try to use qasm2circ in Ubuntu with the command qasm2pdf in terminal, but it outputs that qasm2pdf: command not found. What's wrong? – Eden Harder Sep 6 '14 at 12:13

There is circuitikz for drawing circuits with TiKZ.

share|improve this answer
The circuitikz package is for drawing electrical circuits; quantum circuits are almost completely different. It might be adaptable, but then you probably might as well be using plain TikZ. – Antal Spector-Zabusky Jan 28 '11 at 9:04
That's fair enough. – Mikael Vejdemo-Johansson Jan 29 '11 at 9:49

The image you link to was a diagram I did in TikZ a few years ago. It's not a particularly efficient way of doing it either. These days I'd typeset that using a TikZ matrix environment. The only real option specific to quantum circuits were qasm2circ and q-circuit. I don't like the output they generate though, and TikZ is really the way to go in my opinion. Sure, it may require a few more key strokes, but I think the effort pays off. One important point to make is that TikZ can be slow, but if you get it to externalise TikZ images then it becomes as fast as a normal \includegraphics after a single slow compilation per diagram.

A revised version of the example you link to which may be more inspirational follows:


% TikZ libraries `calc` needed now to tweak bracket.
% Dirac Kets

    % `operator' will only be used by Hadamard (H) gates here.
    % `phase' is used for controlled phase gates (dots).
    % `surround' is used for the background box.
    \tikzstyle{operator} = [draw,fill=white,minimum size=1.5em] 
    \tikzstyle{phase} = [draw,fill,shape=circle,minimum size=5pt,inner sep=0pt]
    \tikzstyle{surround} = [fill=blue!10,thick,draw=black,rounded corners=2mm]
    \matrix[row sep=0.4cm, column sep=0.8cm] (circuit) {
    % First row.
    \node (q1) {\ket{0}}; &[-0.5cm] 
    \node[operator] (H11) {H}; &
    \node[phase] (P12) {}; &
    \node[phase] (P13) {}; &
    \coordinate (end1); \\
    % Second row.
    \node (q2) {\ket{0}}; &
    \node[operator] (H21) {H}; &
    \node[phase] (P22) {}; &
    \node[operator] (H24) {H}; &
    \coordinate (end2);\\
    % Third row.
    \node (q3) {\ket{0}}; &
    \node[operator] (H31) {H}; &
    \node[phase] (P33) {}; &
    \node[operator] (H34) {H}; &
    \coordinate (end3); \\
    % Draw bracket on right with resultant state.
        ($(circuit.north east)-(0cm,0.3cm)$)
        to node[midway,right] (bracket) {$\displaystyle\frac{\ket{000}+\ket{111}}{\sqrt{2}}$}
        ($(circuit.south east)+(0cm,0.3cm)$);
        % Draw background box.
        \node[surround] (background) [fit = (q1) (H31) (bracket)] {};
        % Draw lines.
        \draw[thick] (q1) -- (end1)  (q2) -- (end2) (q3) -- (end3) (P12) -- (P22) (P13) -- (P33);

enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.