# algorithm and tikzpicture side by side

How can I put minipage and tikzpicture side by side? I would like the right picture to centre (now it is aligned to the top) and give it a figure environment so I can give it a caption. This caption should be only under the right picture. What should I do?

    \begin{figure}
\begin{minipage}{0.6\textwidth}
\begin{algorithm}[H]
\caption{Exact Invariant Simulator} \label{alg:eisim}
\begin{algorithmic}
\FOR{$r \in \{1,2,...,R\}$}
\STATE Sample $\theta_i^{(1,r)}$ from $\theta_i\sim p(\theta_i)$
\STATE Sample $Y^{(1,r)}\sim p(\cdot|\theta_i^{(1,r)})$
\FOR{$s \in \{2,3,..,S\}$}
\STATE Sample $\theta_i^{(s,r)}$ from $\theta_i\sim K_i(\cdot|\theta_{-i}^{(s-1,r)})$
\ENDFOR
\STATE Calculate test statistic $T(\theta^{(S,r)}, Y^{(S,r)})$ \footnotemark
\ENDFOR
\end{algorithmic}
\end{algorithm}
\end{minipage}
\hspace{40pt}
\begin{tikzpicture}
\node[latent] (y) {$Y$};
\node[latent, above = of y] (theta) {$\theta$};
\edge {theta} {y}
\end{tikzpicture}
\end{figure}


• You could put the figure in a second minipage (really making it a figure with caption) and use these insights to get your desired vertical alignment. If you want more input, consider posting an MWE, i.e. a document starting with \documentclass and ending with \end{document}. I do not want to have to guess what the settings for your algorithm are. – user121799 Aug 31 '18 at 11:00

The core of that answer is essentially my comment above. The main challenge was to guess all the TikZ styles and options for your algorithm. Do you really think that this is the job of those who try helping you with your problem?

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage[ruled,vlined,linesnumbered]{algorithm2e}
\usepackage{algorithmic}
\usepackage{caption}
\begin{document}
\begin{minipage}{0.6\textwidth}
\begin{algorithm}[H]
\caption{Exact Invariant Simulator} \label{alg:eisim}
\begin{algorithmic}
\FOR{$r \in \{1,2,...,R\}$}
\STATE Sample $\theta_i^{(1,r)}$ from $\theta_i\sim p(\theta_i)$
\STATE Sample $Y^{(1,r)}\sim p(\cdot|\theta_i^{(1,r)})$
\FOR{$s \in \{2,3,..,S\}$}
\STATE Sample $\theta_i^{(s,r)}$ from $\theta_i\sim K_i(\cdot|\theta_{-i}^{(s-1,r)})$
\ENDFOR
\STATE Calculate test statistic $T(\theta^{(S,r)}, Y^{(S,r)})$ \footnotemark
\ENDFOR
\end{algorithmic}
\end{algorithm}
\end{minipage}
\hspace{40pt}
\begin{minipage}{0.2\textwidth}
\centering
\begin{tikzpicture}[ latent/.style={circle, draw ,inner sep=4pt,align=center}]
\node[latent] (y) {$Y$};
\node[latent, above = of y] (theta) {$\theta$};
\draw (theta) edge[-latex] (y);
\node[below=8pt of y] {};
\end{tikzpicture}
\captionof{figure}{A figure}
\end{minipage}
\end{document}