[Tex/LaTex] Setting image in same line as text

graphicshorizontal alignment

I have the line

\noindent\parbox{\textwidth}{{\LARGE\textbf{\name}}}\hfill\begin{figure}[ht!]\includegraphics[width=2cm,height=2cm]{MyPic.jpg}\end{figure}

I want the "name" variable to be on the left, and the image to be on the right of the page. But it turns out the image goes on the left of the next line. How can I make it be in the same line as the "name", but to the right?

EDIT: Removing the begin{figure}

{\noindent\parbox{\textwidth}{{\LARGE\textbf{\name}}}\hfill\includegraphics[width=2cm,height=2cm]{MyPic.jpg}

yields the same result.

Best Answer

You don't need figure environment if not using caption. figure is a float and moves around. You don't need \parbox too.

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\noindent\textbf{name} \hfill\includegraphics[width=2cm]{example-image-a}
\end{document}

enter image description here