3

I want to render a diagram that's like a flow chart, but where arrows go between a symbol in one box to a symbol in another box (as opposed to having an arrow that points from one whole box to another whole box). I want to change the code to render the image below (excuse the ugliness):

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}

\tikzstyle{equation} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black]
\tikzstyle{arrow} = [thick,->,>=stealth]

\begin{document}

\begin{tikzpicture}[node distance=2cm]
\node (get_c) [equation] {$C \leftarrow A + B$};
\node (get_d) [equation, below of=get_c] {$CX - Y \rightarrow D$};
\node (get_x) [equation, below of=get_d] {$X  \leftarrow  F + G$};

\draw [arrow] (get_c) -- (get_d);
\draw [arrow] (get_x) -- (get_d);


\end{tikzpicture}



\end{document}

target image

What I am getting with the code above is this:

what I have so far

1
  • 1
    Edited. I hope this makes it easier for people to offer their input. – Sam May 11 '20 at 21:03
1

You can use matrices to access the expressions in the equation, and place some {} at the right places after & just like in ordinary arrays of the same purpose. calc can be used for the relative alignment. I didn't know if you want to have all the nodes terminate at the same horizontal positions, so I added both options.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{calc,fit,matrix,positioning}

\begin{document}
\begin{tikzpicture}[node distance=2cm,
    equation/.style={rectangle, rounded corners, minimum width=3.5cm, minimum
        height=1cm,text centered, draw=black},
    marrow/.style={thick,-stealth},
    tmat/.style={matrix of math nodes,column sep=0pt,anchor=west,
        nodes={minimum width=0pt,minimum height=0pt,anchor=center,inner xsep=0pt}}]
  \node  [tmat] (get_c) {C&{}\leftarrow A + B\\};
  \node (get_d) [below=of get_c.west,tmat] {C&X&{} - Y \rightarrow D\\};
  \path let \p1=($(get_d-1-2.west)-(get_d-1-1.west)$) in
  node (get_x) [below=of get_d.west,tmat,xshift=\x1] 
     {X&{}  \leftarrow  F + G\\};
  \draw[marrow] (get_c-1-1) -- (get_d-1-1);
  \draw[marrow] (get_x-1-1) -- (get_d-1-2);
  \path foreach \X in {c,d,x} {node[fit=(get_\X),equation]{}};
\begin{scope}[xshift=6cm]
  \node  [tmat] (get_c) {C&{}\leftarrow A + B\\};
  \node (get_d) [below=of get_c.west,tmat] {C&X&{} - Y \rightarrow D\\};
  \path let \p1=($(get_d-1-2.west)-(get_d-1-1.west)$) in
  node (get_x) [below=of get_d.west,tmat,xshift=\x1] 
     {X&{}  \leftarrow  F + G\\};
  \draw[marrow] (get_c-1-1) -- (get_d-1-1);
  \draw[marrow] (get_x-1-1) -- (get_d-1-2);
  \path node[fit=(get_c)(get_d)(get_x)](F){}
  foreach \X in {c,d,x} {node[fit=(get_\X-|F.west)(get_\X-|F.east),equation]{}};
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

2

For complex things you can use Tikz packages Also, I higly recommend to use editors like Mathcha to create this complex images, tables, scripts, 3d images, etc.

So, there are steps to do:

  1. Open Editor for free.

enter image description here

  1. Create the model as you want like the example image below

enter image description here

  1. Export to LaTeX

enter image description here

  1. Add the required packages to your document

    \usepackage{physics} \usepackage{amsmath} \usepackage{tikz} \usepackage{mathdots} \usepackage{yhmath} \usepackage{cancel} \usepackage{color} \usepackage{siunitx} \usepackage{array} \usepackage{multirow} \usepackage{amssymb} \usepackage{gensymb} \usepackage{tabularx} \usepackage{booktabs} \usetikzlibrary{fadings} \usetikzlibrary{patterns} \usetikzlibrary{shadows.blur} \usetikzlibrary{shapes}

  2. Add the script of your content between \begin{document} and \end{document}

enter image description here

  1. In less than 5 minutes you added what you want, results in the image below. enter image description here

Example fullcode:

\documentclass[12pt, letterpaper]{book}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{physics}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{mathdots}
\usepackage{yhmath}
\usepackage{cancel}
\usepackage{color}
\usepackage{siunitx}
\usepackage{array}
\usepackage{multirow}
\usepackage{amssymb}
\usepackage{gensymb}
\usepackage{tabularx}
\usepackage{booktabs}
\usetikzlibrary{fadings}
\usetikzlibrary{patterns}
\usetikzlibrary{shadows.blur}
\usetikzlibrary{shapes}


\title{Title1}
\author{Author1}
\date{May 2020}

\begin{document}
\tikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt        

\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
%uncomment if require: \path (0,300); %set diagram left start at 0, and has height of 300

%Straight Lines [id:da4873436163497318] 
\draw    (169,102) -- (169,160) ;
\draw [shift={(169,162)}, rotate = 270] [color={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=0.75]    (10.93,-3.29) .. controls (6.95,-1.4) and (3.31,-0.3) .. (0,0) .. controls (3.31,0.3) and (6.95,1.4) .. (10.93,3.29)   ;
%Straight Lines [id:da7827018032544013] 
\draw    (282,103) -- (282,161) ;
\draw [shift={(282,163)}, rotate = 270] [color={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=0.75]    (10.93,-3.29) .. controls (6.95,-1.4) and (3.31,-0.3) .. (0,0) .. controls (3.31,0.3) and (6.95,1.4) .. (10.93,3.29)   ;

% Text Node
\draw (57,46.4) node [anchor=north west][inner sep=0.75pt]    {$\frac{a}{b} +\sqrt[3]{a+b} +\int ^{a}_{b} dx+\overbrace{a-b}^{n+1} +\wideparen{ABC} +\widehat{ABC} +\Uparrow H_{2} 0\Uparrow $};
% Text Node
\draw (117,170.4) node [anchor=north west][inner sep=0.75pt]    {$\frac{a}{b} +\sqrt[3]{a+b} +\int ^{a}_{b} dx+\overbrace{a-b}^{n+1} +\wideparen{ABC}$};


\end{tikzpicture}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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