# How to put two metapost graphs in the same row in LuaLatex?

I draw graphs using metapost in LuaLatex. It is more convienient than first use metapost to create graphs and then insert the graphs. But I don't know how to put two graphs in the same row. For example, how to put the following two graphs in the same row? Thank you very much.

\RequirePackage{luatex85}
\documentclass[12pt]{amsart}
\usepackage{float}
\usepackage{luamplib}

\begin{document}

\begin{figure}[H]
\begin{mplibcode}
beginfig(1)
pair A[],L[],R[],N[];
A[1] := (0,2cm);

for i=2 upto 5:
A[i] := A[i-1] rotated -360/5;
endfor;

draw A[1]--A[2];
draw A[2]--A[3];
draw A[3]--A[4];
draw A[4]--A[5];
draw A[5]--A[1];
draw A[1]--A[4];

endfig;
\end{mplibcode}
\end{figure}

\begin{figure}[H]
\begin{mplibcode}
beginfig(1)
pair A[],L[],R[],N[],t[];
path p[];

A[1] := (0,2cm);

for i=2 upto 5:
A[i] := A[i-1] rotated -360/5;
endfor;

draw A[1]..A[2]..A[3]..A[4]..A[5]..A[1];

endfig;
\end{mplibcode}
\end{figure}

\end{document}

• @MarcelKrüger, thank you very much for your suggestions. I edited the post. – Jianrong Li Nov 13 '18 at 16:45
• @MarcelKrüger, I tried to write beginfig(1) and beginfig(2) in the same graph. But it is still in two rows. – Jianrong Li Nov 13 '18 at 16:52

In you document you use two figures. LaTeX never places multiple figures in the same row, so you have to place both mplibcode environments in the same figure environment. (You can also combine them into one mplibcode environment with multiple beginfig(...) endfig; groups, but using different mplibcode environemnts makes it easier to separate the drawings.

Then there is a remaining problem: After \begin{figure}, TeX is in vertical mode. If you add multiple \hboxes (through mplibcode) while vertical mode is active, TeX stacks them vertically. So you want to enter horizontal mode first: Add \leavevmode before the first mplibcode environment:

\RequirePackage{luatex85}
\documentclass[12pt]{amsart}
\usepackage{float}
\usepackage{luamplib}

\begin{document}

\begin{figure}[H]
\leavevmode
\begin{mplibcode}
beginfig(1)
pair A[],L[],R[],N[];
A[1] := (0,2cm);

for i=2 upto 5:
A[i] := A[i-1] rotated -360/5;
endfor;

draw A[1]--A[2];
draw A[2]--A[3];
draw A[3]--A[4];
draw A[4]--A[5];
draw A[5]--A[1];
draw A[1]--A[4];

endfig;
\end{mplibcode}% <- Omit this comment to add a space between the graphs.
\begin{mplibcode}
beginfig(1)
pair A[],L[],R[],N[],t[];
path p[];

A[1] := (0,2cm);

for i=2 upto 5:
A[i] := A[i-1] rotated -360/5;
endfor;

draw A[1]..A[2]..A[3]..A[4]..A[5]..A[1];

endfig;
\end{mplibcode}
\end{figure}

\end{document}