I need to insert something like the following in Latex.
I don't know how to create the arrows (or lines) that connect the letters to each other. Please help me to find a way how to do that. Thanks.
I need to insert something like the following in Latex.
I don't know how to create the arrows (or lines) that connect the letters to each other. Please help me to find a way how to do that. Thanks.
TikZ can also do it using nodes inside a tabular and the nodes are connected using a separate tikzpicture
environment.
\documentclass{article}
\usepackage{tikz,bm}
\newcommand\C[1]{\tikz[remember picture]{\node(#1)[inner sep=0pt]{\sffamily#1};}}
\begin{document}
\begin{tabular}{@{}*7{c@{}}}
\C{A}&\C{B}&\C{C}& $\bm\sim$ &\C{X}&\C{Y}&\C{Z}
\end{tabular}
\begin{tikzpicture}[overlay,remember picture,>=latex,shorten >=1pt,shorten <=1pt,very thin]
\draw[->] (A) --++(0,-10pt) -| (X);
\draw[->] (B) --++(0,-12pt) -| (Y);
\draw[->] (C) --++(0,-14pt) -| (Z);
\end{tikzpicture}
\end{document}
Here's a code with pst-node
:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{pst-node}
\usepackage{auto-pst-pdf} % load this package to compile with pdflatex -shell-escape (MacTeX, TX Live) or pdflatex --enable-write18 (MiKTeX)
\begin{document}
\Large\sffamily \bfseries
\begin{psmatrix}[colsep = 1pt, mnode = r, angle = -90, nodesep = 3pt]
A & B & C & $\boldsymbol{ ∼ }$& X & Y & Z
\psset{arrows = ->, arrowinset = 0.12, linewidth = 0.6pt, linejoin = 1}
\ncbar[arm = 8pt]{1,1}{1,5}
\ncbar[arm = 13pt]{1,2}{1,6}
\ncbar[arm = 18pt]{1,3}{1,7}
\end{psmatrix}
\end{document}
Run with xelatex
\documentclass{article}
\usepackage{fontspec}
\usepackage{pst-node}
\newcommand\C[1]{\rnode{#1}{\textsf{#1}}}
\begin{document}
\C{A}\C{B}\C{C}\textasciitilde\C{X}\C{Y}\C{Z}
\psset{arrows=->,linewidth=0.4pt,angleA=-90,nodesep=2pt}
\ncbar[arm=5pt]{A}{X}
\ncbar[arm=8pt]{B}{Y}
\ncbar[arm=11pt]{C}{Z}
\end{document}
This answer is essentially copied from Tjorbørn T.'s answer and some other sources that are specified in the code. I'll be happy to remove this post once Tjorbørn uploads his answer. Tjorbørn's version of \tikznode
is better than the \rnode
command of pstricks
in that it keeps the ambient math style, e.g. indices stay in scriptstyle
. Here is the code
\documentclass{article}
\usepackage{tikz}
\usepackage{refcount}
\usetikzlibrary{calc}
% from https://tex.stackexchange.com/questions/122415/mathchoice-and-tikzs-remember-picture
\makeatletter
\newcounter{tikznode}
\renewcommand*{\thetikznode}{tikznode@\the\value{tikznode}}
\newcommand*{\tikznodestyle}{%
\refused{\thetikznode}%
\ifcase\getrefbykeydefault{\thetikznode}{}{0} %
\displaystyle
\or\textstyle
\or\scriptstyle
\or\scriptscriptstyle
\fi
}
% from https://tex.stackexchange.com/questions/402462/tikz-equivalent-of-pstricks-command-ncbar-in-text
\newcommand{\tikznode}[2]{%
\ifmmode%
\stepcounter{tikznode}%
\mathchoice
{\def\@currentlabel{0}\label{\thetikznode}}%
{\def\@currentlabel{1}\label{\thetikznode}}%
{\def\@currentlabel{2}\label{\thetikznode}}%
{\def\@currentlabel{3}\label{\thetikznode}}%
\tikz[remember picture,baseline=(#1.base),inner sep=0pt] \node (#1) {$\tikznodestyle #2$};
\else
\tikz[remember picture,baseline=(#1.base),inner sep=0pt] \node (#1) {#2};%
\fi}
\makeatother
% from https://tex.stackexchange.com/questions/402429/how-to-connect-two-parts-using-arrows-or-lines-in-latex
\newcommand{\TikzNCbar}[4][10pt]{%
\tikz[overlay,remember picture]{\draw[#2] (#3) --++(0,-#1) -| (#4);}}
\begin{document}
blabla
$\displaystyle\tikznode{A}{A}\textstyle\tikznode{B}{B}_{\tikznode{C}{C}_{\tikznode{D}{D}}}$
blabla
\tikznode{X}{X}\tikznode{Y}{Y}\tikznode{Z}{Z}\tikznode{W}{W}
blabla
\TikzNCbar{-}{A}{X}
\TikzNCbar[12pt]{->}{B}{Y}
\TikzNCbar[14pt]{<-}{C}{Z}
\TikzNCbar[-14pt]{<->,red}{D}{W}
\end{document}
and this is what it produces:
Obviously, this can also be used for Wick contractions and the like.
ADDENDUM: With the updated version of the tikzmark library this can be made much simpler. This automatically checks the math environment, which made my original answer look a bit lengthy, and spares you from having to type \scriptstyle
and so on, which you might need to do using some of the other answers. (Nor are you required to run this with xelatex
.)
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\newcommand{\TikzNCbar}[4][10pt]{%
\tikz[overlay,remember picture]{\draw[#2] (#3) --++(0,-#1) -| (#4);}}
\begin{document}
blabla
$\displaystyle\tikzmarknode{A}{A}\textstyle\tikzmarknode{B}{B}_{\tikzmarknode{C}{C}_{\tikzmarknode{D}{D}}}$
blabla
\tikzmarknode{X}{X}\tikzmarknode{Y}{Y}\tikzmarknode{Z}{Z}\tikzmarknode{W}{W}
blabla
\TikzNCbar{-}{A}{X}
\TikzNCbar[12pt]{-latex}{B}{Y}
\TikzNCbar[14pt]{latex-}{C}{Z}
\TikzNCbar[-14pt]{latex-latex,red}{D}{W}
\end{document}