# Align to center a minted environment in beamer

I would like to insert some code inside the minted environment when using beamer.

 \documentclass[14pt]{beamer}
\usepackage{minted}

\begin{document}

\begin{frame}[fragile]{}
\begin{figure}
\centering
\begin{minted}[mathescape,
gobble=2,
linenos,
fontsize=\tiny,
framesep=2mm]{ocaml}
let process il =
let module IV = Instr_visitor in
let visit i t = instrument i t in
IV.map_instr IU.is_mem_write visit il
|> insert_instr_list BEFORE !il_update
\end{minted}
\end{figure}
\end{frame}

\end{document}


However, it just cannot be centralized even though I use the centering command. Could anyone shed some light on how to centralize it? Thank you!

Update: This is how it looks here:

Just put minted inside a minipage of sufficient width. Then put this inside a center environment.

(I am not sure why you are using figure. Do you need this to be a float?)

\documentclass[14pt]{beamer}
\usepackage{minted}

\begin{document}

\begin{frame}[fragile]{}

\begin{center}
\begin{minipage}{0.5\textwidth}
\begin{minted}[mathescape,
gobble=2,
linenos,
fontsize=\tiny,
framesep=2mm]{ocaml}
let process il =
let module IV = Instr_visitor in
let visit i t = instrument i t in
IV.map_instr IU.is_mem_write visit il
|> insert_instr_list BEFORE !il_update
\end{minted}
\end{minipage}
\end{center}

\end{frame}

\end{document}

• The problem with this solution is that the width of the minipage needs to be specified manually for each snippet of code. Since the code is still left-aligned within the minipage env. Aug 22, 2019 at 9:13
• @SO_tourist Yes, you are right. But the if you use sufficient width, things are fine. So, there is no harm using a large common width for all. Aug 22, 2019 at 13:14