6

I'm writing a presentation using the beamer class where multiple slides consist of an image on the very right and centered text on the left.

So far I do this using the columns environment:

\documentclass{beamer}
\usepackage{mwe}
\begin{document}
 \begin{frame}
  \begin{columns}
   \begin{column}{.4\textwidth}
    \centering
    centered text\\spanning multiple lines
   \end{column}
   \begin{column}{.6\textwidth}
    \includegraphics[height=\paperheight]{example-image-golden-upright}
   \end{column}
  \end{columns}
 \end{frame}
\end{document}

However, I have to set the column widths manually to make the right column have the same width as the image.

golden ratio slide

As you can see, there is a some white space left right to the image.

How can I make the right column as wide as the image and the left one occupy the remaining space?

If you have a solution without using colums that would also be fine (as long as the image is rightmost and the text centers in the free space left to it).

I need this automated since I have that multiple times using many pictures with different aspect-ratios. So the column widths need to be different on each slide.

1
  • 1
    Welcome to TeX.SX! You can add images; use the interface and remove the ! in front of the link. A user with suitable privileges will reinsert it.
    – egreg
    Jul 26 '13 at 10:08
4

It's unclear if you want to use overlays; if you don't, here's the definition of an environment that does the necessary computations. I add also a “less automatized” solution.

\documentclass{beamer}
\usepackage{mwe}

\newlength{\mycolwidth}
\newsavebox{\mycolwidthbox}
%% Better way
\newenvironment{picturecolumn}[2][]
 {\sbox\mycolwidthbox{\includegraphics[#1]{#2}}%
  \setlength{\mycolwidth}{\wd\mycolwidthbox}%
  \begin{columns}
  \begin{column}{\dimexpr\textwidth-\mycolwidth}
  \centering}
 {\end{column}
  \begin{column}{\mycolwidth}
  \usebox{\mycolwidthbox}
  \end{column}
  \end{columns}}

%% Simpler way
\newcommand{\setmycolwidth}[2][]{%
  \settowidth{\mycolwidth}{\includegraphics[#1]{#2}}%
}

\begin{document}
\begin{frame}

\begin{picturecolumn}[height=\dimexpr\paperheight-5pt]{example-image-golden-upright}
\centering
centered text\\
spanning multiple lines
\end{picturecolumn}
\end{frame}

\begin{frame}

\setmycolwidth[height=\paperheight]{example-image-golden-upright}

\begin{columns}
\begin{column}{\dimexpr\textwidth-\mycolwidth}
\centering
centered text\\
spanning multiple lines
\end{column}
\begin{column}{\mycolwidth}
\includegraphics[height=\paperheight]{example-image-golden-upright}
\end{column}
\end{columns}
\end{frame}

\end{document}

enter image description here

1
  • I was not going to use overlays, so this solution worked perfectly for me. Thx!
    – mschilli
    Jul 26 '13 at 10:51
2

I hope I understood that right, that you want to get rid of the space right to the image, here is a solution involving parboxes.

\documentclass{beamer}
\usepackage{mwe}
\usepackage{calc}
%\usepackage{geometry} will be loaded with beamer
\newlength\rightcolumn
\begin{document}
\newgeometry{margin=0pt,includeall}
 \begin{frame}[plain]
 \settowidth{\rightcolumn}{\includegraphics[height=\paperheight]{example-image-golden-upright}}
   \parbox[t][\paperheight][c]{\paperwidth-\rightcolumn}{%
    \centering%
    centered text\\spanning multiple lines
   }%
   \parbox[t][\paperheight][c]{\rightcolumn}{%
    \includegraphics[height=\paperheight]{example-image-golden-upright}
   }%
 \end{frame}
\end{document}

And this results in: enter image description here

2
  • This seems to work, too. Is there any improvement by using parboxes instead of columns? If so, I guess I could adjust egregs environment definition to use parboxes.
    – mschilli
    Jul 26 '13 at 11:53
  • I like using parboxes, makes me feel having everything under control. There is not more improvement over using columns, but as parboxes are a very lowlevel command you cannot go wrong in making things messi in other environments. I usually find it much simpler writing code for a parbox than adapting an environment. But that is just flavour. Jul 26 '13 at 16:23

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.