1

Code:

\documentclass{beamer}
\begin{document}

\begin{frame}[t,fragile]
  \begin{columns}[T]
    \begin{column}{0.45\textwidth}
      \begin{verbatim}
      Lorem ipsum dolor sit
      \end{verbatim}
    \end{column}
    \begin{column}{0.45\textwidth}
      \includegraphics[width=\textwidth]{320px-Herald_of_Free_Enterprise.jpg}
    \end{column}
  \end{columns}
\end{frame}

\end{document}

Link to the image used in the above code:

https://upload.wikimedia.org/wikipedia/commons/thumb/b/b3/Herald_of_Free_Enterprise.jpg/320px-Herald_of_Free_Enterprise.jpg

Output:

enter image description here

Question:

The top of the verbatim text and the top of the image are not aligned even after using T option for columns. How can I vertically align them to the top?

1

I'd set the verbatim content in a box (via lrbox) before using it (via \usebox):

enter image description here

\documentclass{beamer}

\begin{document}

\begin{frame}[t,fragile]
  \begin{columns}[T]
    \begin{column}{0.45\textwidth}
      \begin{verbatim}
      Lorem ipsum dolor sit
      \end{verbatim}
    \end{column}
    \begin{column}{0.45\textwidth}
      \includegraphics[width=\linewidth]{example-image}
    \end{column}
  \end{columns}
\end{frame}

\newsavebox{\verbbox}
\begin{lrbox}{\verbbox}
\begin{minipage}{.45\linewidth}
\begin{verbatim}
Lorem ipsum dolor sit
\end{verbatim}
\end{minipage}
\end{lrbox}

\begin{frame}[t]
  \begin{columns}[T]
    \begin{column}{0.45\textwidth}
      \usebox{\verbbox}
    \end{column}
    \begin{column}{0.45\textwidth}
      \includegraphics[width=\linewidth]{example-image}
    \end{column}
  \end{columns}
\end{frame}

\end{document}

Note that the difference in horizontal alignment between the two Lorem ipsum dolor sit phrases stems from the indentation within the verbatim environment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.