3

I have been using TikZ to draw this type of equations

enter image description here

using this

\begin{equation}
\begin{tikzpicture}[
  inner sep=0pt,
  outer sep=0pt,
  baseline=(hat.base),
]
  \path[every node/.append style={anchor=base west}]
    (0,0)
    \foreach \name/\code in {
      bra0/,
      bra/Z,
      sub/_1,
      sub2/_2,
      angle/%
      } {
      node (\name) {$\code$}
      (\name.base east)
    }
  ;
  \path[
    every node/.append style={
      anchor=base,
      font=\slshape\scriptsize,
    },
  ]
    (bra0.base) -- node[below=3\baselineskip] (geb_2) {12} (ket)
  ;
  \begin{scope}[
    >={Stealth[length=5pt]},
    thick,
    rounded corners=0pt,
    shorten <=.3em,
    shorten >=.3em,
  ]

    \def\GebArrow#1#2#3{
      \draw[<->]
        (#2.north) ++(0, .3em) coordinate (tmp)
        (#1) |- (tmp) -| (#3)
      ;%
    }
    \GebArrow{sub2}{geb_2}{sub}
  \end{scope}
\end{tikzpicture}
\end{equation}

but I can't seem to find the way to do this equation

enter image description here

which seems easier but I don't know how to produce the simple arrows that don't connect.

2 Answers 2

4

I am not sure I understand what your code does. However, it is really straightforward to reproduce your handwritten formula using the tikzmark library. It will be even more straightforward when this library contains \tikzmarknode, and I will be happy to update my code when the update is officially on CTAN. Until then you could use

\documentclass{article}
\usepackage{amsmath,amssymb,braket,tikz}
\usetikzlibrary{tikzmark,calc}
\begin{document}
\begin{equation}
 \phi_{\tikzmark{1-1}1\tikzmark{1-2}}
 ~=~x_{\tikzmark{2-1}1\tikzmark{2-2}1\tikzmark{2-3}}\,
 \psi_{\tikzmark{3-1}1\tikzmark{3-2}}+
 x_{\tikzmark{4-1}1\tikzmark{4-2}2\tikzmark{4-3}}\,
 \psi_{\tikzmark{5-1}2\tikzmark{5-2}}\;.
\end{equation}
\begin{tikzpicture}[overlay,remember picture]
\foreach \X in {1,2,4}
{ \draw[latex-,shorten <=1pt] ($(pic cs:\X-1)!0.5!(pic cs:\X-2)$) 
 -- ++ (0,-1) node[below]{$\scriptstyle1$};}
\foreach \X [evaluate=\X as \Y using {int(\X+1)},count=\Z]in {2,4}
{\draw[latex-latex,shorten <=1pt,shorten >=1pt] 
 ($(pic cs:\X-2)!0.5!(pic cs:\X-3)$) 
 -- ++ (0,-.5) -| ($(pic cs:\Y-1)!0.5!(pic cs:\Y-2)$) 
 node[below,pos=0.25]{$\scriptstyle\Z\Z$};}
\end{tikzpicture}
\end{document}

enter image description here

And here is a preview to the upcoming version of tikzmark. (I apologize for not having read the manual, this new version makes things really easy. WOW!)

\documentclass{article}
\usepackage{amsmath,tikz}
\usetikzlibrary{tikzmark}
\begin{document}
\begin{equation}
 \phi_{\tikzmarknode{11}{1}}
 ~=~x_{\tikzmarknode{21}{1}\tikzmarknode{22}{1}}\,
 \psi_{\tikzmarknode{31}{1}}+
 x_{\tikzmarknode{41}{1}\tikzmarknode{42}{2}}\,
 \psi_{\tikzmarknode{51}{2}}\;.
\begin{tikzpicture}[remember picture,overlay]
\foreach \X in {1,2,4}
{ \draw[latex-,shorten <=1pt] (\X1) 
 -- ++ (0,-1) node[below] (l\X) {$\scriptstyle1$};}
\foreach \X [evaluate=\X as \Y using {int(\X+1)},count=\Z]in {2,4}
{\draw[latex-latex,shorten <=1pt,shorten >=1pt] 
 (\X2)  -- ++ (0,-.5) -| (\Y1)
 node[below,pos=0.25]{$\scriptstyle\Z\Z$};}
\end{tikzpicture}
\end{equation}
\end{document}
2
  • 1
    You're mixing syntaxes for referring to the coordinates. You've used the pic cs coordinates, which can only be used for coordinates defined by \tikzmark itself. \tikzmarknode defines an ordinary node-type coordinate. Just delete the pic cs: and it works. Sep 18, 2018 at 19:28
  • The documentation is probably woefully lacking, particularly in this case with a new feature. So this is all useful stuff for me. Sep 18, 2018 at 20:08
4

Another short code with pstricks:

\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{pst-node, auto-pst-pdf}

\begin{document}

    \[ \begin{postscript}
    \everypsbox{\scriptstyle}
    %% Some nodes
    \phi_{\rnode[b]{F}{1}} = x_{\rnode[b]{a}{1}\rnode[b]{b}{1}}\varphi_{\rnode[b]{c}{1}} + x_{\rnode[b]{d}{1} \rnode[b]{e}{2}}\varphi_{\rnode[b]{g}{2}}
    %% Remaining nodes and connections
    \psset{angle=-90, linewidth=0.6pt, linejoin=1, arm=4.5mm, arrows=<->, arrowinset=0.1, nodesep=2pt, labelsep=1.5pt}
    \foreach \s/\t in {F/G, a/A, d/D}{\uput{1cm}[d](\s){\rnode[t]{\t}{1}}\ncline[arrows=->]{\t}{\s}}
    \ncbar{b}{c}\nbput{11}
    \ncbar{e}{g}\nbput{22}
    \end{postscript} \]%

\end{document} 

enter image description here

You must log in to answer this question.

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