Drawing a line through a box in tikz
Premise: I'm not a physicist, I do not know what you're talking about.
You can use the option execute at end picture={...}
to add some code to be executed after your tikzcd
.
\tikzcdmatrixname
is the name of the TikZ matrix the tikzcd
is translated into.
\tikzcdmatrixname-r-c
is the name of the cell of the TikZ matrix at the rth row and cth column.
Maybe there is a better method (without manual adjustments xshift
and yshift
) but I don't know it.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{quantikz}
\begin{document}
\begin{tikzcd}[execute at
end picture={
\draw[thick] ([yshift=-23.8pt,
xshift=39pt]\tikzcdmatrixname-1-1.north
west) --
([yshift=-23.8pt, xshift=-39pt]\tikzcdmatrixname-1-5.north west);
}]
& \gate[wires=2]{J_{12}} & \gate[wires=3]{\raisebox{4pt}{$J_{13}$}} &
\qw & \qw \\
& & &
\gate[wires=2]{J_{23}} & \qw \\
& \qw &
& & \qw
\end{tikzcd}
\end{document}
Here is a pure TikZ alternative without fine-tuning with a matrix
:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix, fit}
\tikzset{gate/.style={rectangle, thick, fill=white,align=center, draw, text width=1.5em}}
\begin{document}
\begin{tikzpicture}
\matrix[matrix of nodes,
nodes in empty cells,
column sep=2.5em,
row sep=4ex] (mymatr) {
&[-1em]&&&[-1em]\\
&&&&\\
&&&&\\};
\draw[thick] (mymatr-1-1) -- (mymatr-1-5);
\draw[thick] (mymatr-3-1) -- (mymatr-3-5);
\node[fit=(mymatr-1-3)(mymatr-3-3), gate, text height=5ex] {$J_{13}$};
\draw[thick] (mymatr-2-1) -- (mymatr-2-5);
\node[fit=(mymatr-1-2)(mymatr-2-2), gate] {$J_{12}$};
\node[fit=(mymatr-2-4)(mymatr-3-4), gate] {$J_{23}$};
\end{tikzpicture}
\end{document}
Here is a pure TikZ alternative without fine-tuning and without any matrix
:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{gate/.style={rectangle, thick, align=center, draw, text width=1.5em}}
\begin{document}
\begin{tikzpicture}[node distance=1.5em]
\node[gate, minimum height=18ex, text height=0ex] (j13) {$J_{13}$};
\node[left =of j13.north west, anchor=north east, minimum height=12ex, gate] (j12) {$J_{12}$};
\node[right =of j13.south east, anchor=south west, minimum height=12ex, gate] (j23) {$J_{23}$};
\coordinate (start1) at ([yshift=-2ex]j12.north west);
\coordinate (end1) at ([xshift=1em]j23.east |- start1);
\draw[thick] (start1) -- +(-1em, 0);
\draw[thick] (start1 -| j12.east) -- (start1 -| j13.west);
\draw[thick] (start1 -| j13.east) -- (end1);
\coordinate (start2) at ([yshift=2ex]j12.south west);
\draw[thick] (start2) -- +(-1em, 0);
\draw[thick] (start2 -| j12.east) --
(start2 -| j23.west);
\draw[thick] (start2 -| j23.east) --
+(1em, 0);
\coordinate (start3) at ([yshift=2ex]j23.south west -| start1);
\draw[thick] (start3) +(-1em, 0) -- (start3 -| j13.west) ;
\draw[thick] (start3 -| j13.east) --
(start3 -| j23.west);
\draw[thick] (start3 -| j13.east) --
(start3 -| j23.west);
\draw[thick] (start3 -| j23.east) --
+(1em, 0);
\end{tikzpicture}
\end{document}