2

The following is the code and its output. The output doesn't look well. If they are both aligned horizontally by their left and then centered in the frame, it will looks better. But how? (The image is centered in the frame.)

\documentclass{beamer}
\usepackage{algorithm2e}

\begin{document}
 \begin{frame}
  \begin{center}
    \includegraphics[width=0.5\textwidth, height=3cm]{fig4}

    \medskip

    %\fbox{
    \begin{minipage}{0.66\textwidth}
      \begin{algorithm}[H]
    \DontPrintSemicolon
    \KwSty{type} val : \KwSty{real}$[k]$\;
    \KwSty{type} ind : \KwSty{int}$[k]$\;
    \KwSty{type} ptr : \KwSty{int}$[s+1]$\;
    \everypar={\nl}
    \For{$d=0$ \KwTo $ptr[d+1]-ptr[d]$}{
      \For{$l=0$ \KwTo $ptr[d+1]-prt[d]$}{
        $z[l] \leftarrow z[l]+val[prt[d]+l] \cdot x[\textcolor{red}{ind[ptr[d]+l]}]$\;
      }
    }
      \end{algorithm}
    \end{minipage}
   %}
  \end{center}

\end{frame}

\end{document}

enter image description here

Werner
  • 603,163
Yulong Ao
  • 723

1 Answers1

3

Set both items in a minipage of similar widths. Then adjustments to the horizontal alignment should match, since the minipage has a default left-alignment (actually justified):

enter image description here

\documentclass{beamer}
\let\Tiny\tiny% http://tex.stackexchange.com/a/94159/5764
\usepackage{algorithm2e}

\begin{document}
\begin{frame}

\begin{center}
  \begin{minipage}{.8\linewidth}
    \includegraphics[width=0.5\textwidth, height=3cm]{example-image}
  \end{minipage}

  \medskip

  \begin{minipage}{.8\linewidth}
    \begin{algorithm}[H]
      \DontPrintSemicolon
      \KwSty{type} val : \KwSty{real}$[k]$\;
      \KwSty{type} ind : \KwSty{int}$[k]$\;
      \KwSty{type} ptr : \KwSty{int}$[s+1]$\;
      \everypar={\nl}
      \For{$d=0$ \KwTo $ptr[d+1]-ptr[d]$}{
        \For{$l=0$ \KwTo $ptr[d+1]-prt[d]$}{
          $z[l] \leftarrow z[l]+val[prt[d]+l] \cdot x[\textcolor{red}{ind[ptr[d]+l]}]$\;
        }
      }
    \end{algorithm}
  \end{minipage}
\end{center}

\end{frame}

\end{document}
Werner
  • 603,163