我想在演示文稿中将标题放在图片的右侧/左侧。但是,由于和beamer
之间不兼容,以下代码不起作用。beamer
floatrow
\documentclass{beamer}
\setbeamertemplate{caption}{\insertcaption}
\usepackage{floatrow}
\begin{document}
\begin{frame}
\begin{figure}
\floatbox[{\capbeside\thisfloatsetup{capbesideposition={right,bottom},capbesidewidth=0.4\textwidth}}]{figure}[\FBwidth]
{\caption{Example image}\label{fig:example}}
{\includegraphics[width=0.5\textwidth]{example-image}}
%\includegraphics[width=0.5\textwidth]{example-image}
%\caption{Example image}
%\label{fig:example}
\end{figure}
\end{frame}
\end{document}
答案1
以下是使用环境的解决方案columns
:
\documentclass{beamer}
\setbeamertemplate{caption}{\insertcaption}
\begin{document}
\begin{frame}
\begin{figure}
\begin{columns}
\column{.6\linewidth}
\includegraphics[width=\textwidth]{example-image}
\column{.3\linewidth}
\caption{Example image}
\label{fig:example right}
\end{columns}
\end{figure}
\end{frame}
\begin{frame}
\begin{figure}
\begin{columns}
\column{.3\linewidth}
\caption{Example image}
\label{fig:example left}
\column{.6\linewidth}
\includegraphics[width=\textwidth]{example-image}
\end{columns}
\end{figure}
\end{frame}
\end{document}
编辑
在这里,我定义了一个带有 3 个参数的新命令(\figurewithcaptionatside
)(第一个参数是可选的):
选项:(
caption position
垂直位置:c
,t
或b
),caption on the left
,caption on the right
,caption width
,image width
,制作标题的材料,
制作图形的材料。
我用来pgfkeys
管理选项。
用法:
\begin{figure}
\figurewithcaptionatside
[caption position=t,caption on the left]
{\caption{Example image with left caption}\label{fig:example left}}
{\includegraphics[width=\textwidth]{example-image}}
\end{figure}
完整代码:
\documentclass{beamer}
\makeatletter
\newif\ifcaptionsideisleft
\pgfset{
fwcas@/.is family,
fwcas@,
caption position/.is choice,
caption position/c/.code={
\def\fwcas@captionposition{c}\def\fwcas@imageposition{c}
},
caption position/b/.code={
\def\fwcas@captionposition{b}\def\fwcas@imageposition{b}
},
caption position/t/.code={
\def\fwcas@captionposition{T}\def\fwcas@imageposition{T}
},
caption left side@/.is if=captionsideisleft,
caption on the left/.style={caption left side@=true},
caption on the right/.style={caption left side@=false},
caption width/.code={
\pgfmathsetmacro\fwcas@captionwidth{#1}
},
image width/.code={
\pgfmathsetmacro\fwcas@imagewidth{#1}
},
every figurewithcaptionatside/.style={
caption position=c,
caption on the left,
caption width=.3\linewidth,
image width=.7\linewidth,
},
}
\newcommand\figurewithcaptionatside[3][]{
\pgfset{fwcas@,every figurewithcaptionatside,#1}
\ifcaptionsideisleft
\begin{columns}
\column[\fwcas@captionposition]{\fwcas@captionwidth pt}
#2
\column[\fwcas@imageposition]{\fwcas@imagewidth pt}
#3
\end{columns}
\else
\begin{columns}
\column[\fwcas@imageposition]{\fwcas@imagewidth pt}
#3
\column[\fwcas@captionposition]{\fwcas@captionwidth pt}
#2
\end{columns}
\fi
}
\makeatother
\setbeamertemplate{caption}{\insertcaption}
\begin{document}
\begin{frame}
\begin{figure}
\figurewithcaptionatside
{\caption{Example image with default value}\label{fig:example}}
{\includegraphics[width=\textwidth]{example-image}}
\end{figure}
\end{frame}
\begin{frame}
\begin{figure}
\figurewithcaptionatside
[caption position=t,caption on the left,
caption width=.5\linewidth,
image width=.5\linewidth,
]
{\caption{Example image with left caption}\label{fig:example left}}
{\includegraphics[width=\textwidth]{example-image}}
\end{figure}
\end{frame}
\begin{frame}
\begin{figure}
\figurewithcaptionatside
[caption on the right,caption position=b]
{\caption{Example image with right caption}\label{fig:example right}}
{\includegraphics[width=\textwidth]{example-image}}
\end{figure}
\end{frame}
\end{document}