[Tex/LaTex] Customizing \fill and line in TikZ

funtikz-arrowstikz-pgf

How I can draw these (flexible) nodes and arrow? (as in this presentation)

enter image description here

A MWE:

\documentclass{beamer}
\usepackage{tikz}
\usetheme{CambridgeUS}
\usetikzlibrary{calc}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usetikzlibrary{arrows.meta} %
\tikzset{ vnode/.style={draw,text=black , line width=4pt,color=gray!50!black!50},
          vvnode/.style={color=gray!50!black!50,text=black , line width=4pt}, 
          vfill/.style={color=black,text=black,fill=red!10!gray!30!blue!50,line width=4pt,},
          varrow/.style={Latex-Latex, text=black,line width=3pt,color=gray!50!black!50},
          vline/.style={line width=1.6pt,color=red!10!gray!30!blue!50},
          }
\newcommand{\uline}[1]{
    \tikz[baseline=(uline.base)]{
        \node[inner sep=1pt,outer sep=0pt] (uline) {#1};
        \draw[vline] (uline.south west) -- (uline.south east);
    }%
    }

\begin{document}
\begin{frame}{}
 \begin{tikzpicture}
    \node[vfill ] at (0,0) { $\left(\frac\delta{\delta h_0}-2m \frac\delta{\delta F_0} \right)S=0,\quad
    \left(\frac\delta{\delta \tau_0}-m \frac\delta{\delta \chi_0} \right)S=0 $};
 \end{tikzpicture}
\begin{tikzpicture}[]%remember picture
 \node[vnode] at (0,0) {
 \begin{tikzpicture}
    \node[ vvnode,name=bbb,align=left] at (-1,-2) {Operators\\
                      $\begin{aligned}\mathcal O=& O_\theta + \theta \uline{$O_\chi$} +\theta^2 \uline{$O_F$} \\
                                    \mathcal F\mathcal Z=& \left\{ \uline{$T_{\mu\nu}$}, \uline{$S_\mu$}, j_\mu\right\}  
                                      \end{aligned} $}; 
    \draw[varrow,] (1.6,-2) to (3.9,-2); 
    \node[ vvnode,align=left] at (5.9,-2) {$5d$ fields\\
                                 $\begin{aligned} \mathcal H=& \left\{ \phi, \uline{$\chi$}, \uline{$F$} \right\}  \\
                                      \mathcal G=&  \left\{ \uline{$g_{\mu\nu}$}, \uline{$\Psi_\mu$}, A_\mu\right\} 
                                  \end{aligned} $};
  \end{tikzpicture}
  };
\end{tikzpicture}
\end{frame}
\end{document}

enter image description here

Best Answer

Here's a start, based on my answer at Handwritten comments and annotations in margin. There, I make use of the Teen SPirit font, which is a handwritten font (by way of \fontfamily{fts}\selectfont). Looking at the glyph set of that font (page 2 of http://www.tug.dk/FontCatalogue/teenspirit/teenspirit.pdf), there are several choices for hand drawn line (e.g., glyphs 40, 47, 73, 108, 124, etc.). I chose glyph 47

enter image description here

Then, I created the macro \handxform for rotating and scaling a glyph, where the vertical scale is given by a factor and the horizontal scale is given by a desired length (EDITED to work around scaling limitation, so that actual width specified is honored). The macro \handline[<thickness-scale>]{<length>} passes glyph 47 to \handxform, along with the user-specified scaling information, and the rotations necessary to turn glyph 47 into a horizontal aspect at the proper elevation.

All of the handdrawn lines in the MWE below are scaled, rotated versions of glyph 47.

EDITED to add \handstealthleftrightarrow[<thickness-scale>]{<length>} to the mix, by stringing together glyph 60 and its mirror image:

enter image description here

EDITED to add \handbox[<thickness-scale>]{<length>}{<height>}, which works by stringing together 4 \handlines.

\documentclass{beamer}
\usepackage{tikz}
\usetheme{CambridgeUS}
\usetikzlibrary{calc}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usetikzlibrary{arrows.meta} %
\tikzset{vvnode/.style={color=gray!50!black!50,text=black , line width=4pt}}
\newcommand{\uline}[2][blue!30!red]{
  \setbox0=\hbox{#2}%
  \stackunder[2pt]{\copy0}{\color{#1}\handline[2]{\wd0}}%
    }
\usepackage{emerald,scalerel,stackengine}
\usepackage[T1]{fontenc}
\newcommand\handline[2][1]{%
  \kern-.25ex\smash{\handxform{0ex}{-.32ex}{90}{15}{47}{#1}{#2}}}
\newcommand\handstealthrightarrow[2][1]{%
  \handxform{.51ex}{-0.2ex}{ 90}{ 80}{60}{#1}{#2}}
\newcommand\handstealthleftarrow [2][1]{%
  \handxform{.49ex}{0.40ex}{-90}{ 80}{60}{#1}{#2}}
\newcommand\handstealthleftrightarrow[2][1]{%
  \handstealthleftarrow[#1]{.5\dimexpr#2}\kern-0.11\dimexpr#2\relax%
    \handstealthrightarrow[#1]{.5\dimexpr#2}}
\newcommand\handbox[3][1]{%
  \rotatebox{90}{\handline[#1]{#3}}\kern-.006\dimexpr#1\dimexpr#2\relax\relax%
  \stackon[\dimexpr1\dimexpr#3\relax-\dimexpr.6ex]{\handline[#1]{#2}}{%
    \handline[#1]{#2}}%
  \kern-#1\dimexpr.3ex%
  \rotatebox{90}{\handline[#1]{#3}}%
}
\newcommand\handxform[7]{%
  \raisebox{#1}{\fontfamily{fts}\selectfont\scalebox{4}[#6]{%
  \raisebox{#2}{\rotatebox{#3}{\stretchto{\rotatebox{#4}{\char#5}}{.25\dimexpr#7}}}}}}
\begin{document}
\begin{frame}{}
 \begin{tikzpicture}
    \node[ ] at (0,0) {\rlap{\color{blue!20}\handline[24]{3.3in}}
    $\left(\frac\delta{\delta h_0}-2m \frac\delta{\delta F_0} \right)S=0,\quad
    \left(\frac\delta{\delta \tau_0}-m \frac\delta{\delta \chi_0} \right)S=0 $};
 \end{tikzpicture}\smallskip

\begin{tikzpicture}[]%remember picture
 \node at (0,0) {
 \begin{tikzpicture}
    \node[ vvnode,name=bbb,align=left] at (-1,-2) {Operators\\
                      $\begin{aligned}\mathcal O=& O_\theta + \theta \uline{$O_\chi$} +\theta^2 \uline{$O_F$} \\
                                    \mathcal F\mathcal Z=& \left\{ \uline{$T_{\mu\nu}$}, \uline{$S_\mu$}, j_\mu\right\}  
                                      \end{aligned} $}; 
    \node at (2.7,-2) {\color{gray}\handstealthleftrightarrow[2]{1in}};%
    \node at (2.2,-2) {\color{gray}\handbox[5]{4.7in}{1in}};
    \node[ vvnode,align=left] at (5.9,-2) {$5d$ fields\\
                                 $\begin{aligned} \mathcal H=& \left\{ \phi, \uline{$\chi$}, \uline{$F$} \right\}  \\
                                      \mathcal G=&  \left\{ \uline{$g_{\mu\nu}$}, \uline{$\Psi_\mu$}, A_\mu\right\} 
                                  \end{aligned} $};
  \end{tikzpicture}
  };
\end{tikzpicture}
\end{frame}
\begin{frame}
\handbox[3]{2.5in}{.7in}\quad
\handbox[1]{1in}{.7in}\medskip

\handbox[5]{4.5in}{.7in}

\handstealthleftrightarrow[1]{.5in}
\handstealthleftrightarrow[3]{3in}

\mbox{}\handline[1]{1in}
\handline[10]{1in}
\handline[5]{1in}

\the\textwidth

\noindent\fbox{\rule{.9\textwidth}{1pt}}

\noindent\fbox{\handline[1]{.9\textwidth}}
\end{frame}
\end{document}

enter image description here

enter image description here

DISCUSSION

There are some questions below on how to tune the particular shape of the "swish." However, that belies a fundamental misunderstanding of what is done here. All that I am doing is taking a font's glyph, and rotating/stretching/rerotating/translating/restretching/retranslating it, to achieve a desired size and orientation. The shape of the swish is driven totally by the original glyph selected, which in this answer came from the Teen Spirit font.

As an example, if I redefine \handxform to not use the Teen Spirit font, and to instead of the specified glyph, use a simple \rule{1pt}{5pt}:

\newcommand\handxform[7]{%
  \raisebox{#1}{\scalebox{4}[#6]{%
  \raisebox{#2}{\rotatebox{#3}{\stretchto{\rotatebox{#4}{\rule{1pt}{5pt}}}{.25\dimexpr#7}}}}}}

you will see the results change accordingly, where the new swish is comprised of a transformed \rule instead of a transformed glyph 47 or 60.

enter image description here

Therefore, to obtain other shapes, other suitable glyphs must be found from other fonts, if this technique is to be employed. Alternately, someone could use tikz to design a desired swish, and that could be incorporated into a slightly redefined \handxform macro.

As an illustrative case, I can even use an \includegraphics as the swish. Idealy it would be a transparent png, but here I just took the image at the top of this page, saved it as a jpeg, tried to expunge the black text, and used that as my swish. Obviously, the definitions and parameters had to be reworked to accommodate this (especially since the aspect ratio is different), but the result looks as expected:

enter image description here

After saving a large version of the image as greenswish.jpg, The code for the above is:

\documentclass{beamer}
\usepackage{tikz}
\usetheme{CambridgeUS}
\usetikzlibrary{calc}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usetikzlibrary{arrows.meta} %
\tikzset{vvnode/.style={color=gray!50!black!50,text=black , line width=4pt}}
\newcommand{\uline}[2][blue!30!red]{
  \setbox0=\hbox{#2}%
  \stackunder[2pt]{\copy0}{\color{#1}\handline[.2]{\wd0}}%
    }
\usepackage{emerald,scalerel,stackengine}
\usepackage[T1]{fontenc}
\newcommand\handline[2][.1]{%
  \kern-.2ex\smash{\handxform{.0ex}{.6ex}{-90}{90}{%
    \includegraphics[scale=.1]{greenswish}}{#1}{#2}}}
\newcommand\handstealthrightarrow[2][1]{%
  \handxform{.51ex}{-0.2ex}{ 90}{ 80}{\char60}{#1}{#2}}
\newcommand\handstealthleftarrow [2][1]{%
  \handxform{.49ex}{0.40ex}{-90}{ 80}{\char60}{#1}{#2}}
\newcommand\handstealthleftrightarrow[2][1]{%
  \handstealthleftarrow[#1]{.5\dimexpr#2}\kern-0.11\dimexpr#2\relax%
    \handstealthrightarrow[#1]{.5\dimexpr#2}}
\newcommand\handbox[3][.1]{%
  \rotatebox{90}{\handline[#1]{#3}}\kern-.006\dimexpr#1\dimexpr#2\relax\relax%
  \stackon[\dimexpr1\dimexpr#3\relax+.4ex]{\handline[#1]{#2}}{%
    \handline[#1]{#2}}%
  \kern-#1\dimexpr.3ex%
  \rotatebox{90}{\handline[#1]{#3}}%
}
\newcommand\handxform[7]{%
  \raisebox{#1}{\fontfamily{fts}\selectfont\scalebox{4}[#6]{%
  \raisebox{#2}{\rotatebox{#3}{\stretchto{\rotatebox{#4}{#5}}{.25\dimexpr#7}}}}}}
\begin{document}
\begin{frame}{}
 \begin{tikzpicture}
    \node[ ] at (0,0) {\rlap{\color{blue!20}\handline[3]{3.42in}}
    $\left(\frac\delta{\delta h_0}-2m \frac\delta{\delta F_0} \right)S=0,\quad
    \left(\frac\delta{\delta \tau_0}-m \frac\delta{\delta \chi_0} \right)S=0 $};
 \end{tikzpicture}\smallskip

\begin{tikzpicture}[]%remember picture
 \node at (0,0) {
 \begin{tikzpicture}
    \node[ vvnode,name=bbb,align=left] at (-1,-2) {Operators\\
                      $\begin{aligned}\mathcal O=& O_\theta + \theta \uline{$O_\chi$} +\theta^2 \uline{$O_F$} \\
                                    \mathcal F\mathcal Z=& \left\{ \uline{$T_{\mu\nu}$}, \uline{$S_\mu$}, j_\mu\right\}  
                                      \end{aligned} $}; 
    \node at (2.7,-2) {\color{gray}\handstealthleftrightarrow[2]{1in}};%
    \node at (2.2,-2) {\color{gray}\handbox[.5]{4.7in}{1in}};
    \node[ vvnode,align=left] at (5.9,-2) {$5d$ fields\\
                                 $\begin{aligned} \mathcal H=& \left\{ \phi, \uline{$\chi$}, \uline{$F$} \right\}  \\
                                      \mathcal G=&  \left\{ \uline{$g_{\mu\nu}$}, \uline{$\Psi_\mu$}, A_\mu\right\} 
                                  \end{aligned} $};
  \end{tikzpicture}
  };
\end{tikzpicture}
\end{frame}
\begin{frame}
\handbox[.3]{2.5in}{.7in}\quad
\handbox[.1]{1in}{.7in}\medskip

\handbox[.1]{4.5in}{.7in}

\handstealthleftrightarrow[.1]{.5in}
\handstealthleftrightarrow[.3]{3in}

\mbox{}\handline[.1]{1in}
\handline[1.0]{1in}
\handline[.5]{1in}

\the\textwidth

\noindent\fbox{\rule{.9\textwidth}{1pt}}

\noindent\fbox{\handline[.1]{.9\textwidth}}
\end{frame}
\end{document}