由于 \framebox 导致 beamer 出现错误消息

由于 \framebox 导致 beamer 出现错误消息

看看下面的代码。它一直给我一个错误,我不知道为什么。我只知道这是由于函数引起的\framework。有人知道如何解决这个问题吗?

\begin{frame}[t]{Bootstrap}
\begin{itemize}
\item Compute variability of parameter by means of resampling with replacement
\item Standard error necessary to compute prediction error 
\item Algorithm Efron and Tibshirani (1994) 
\item $\hat{\theta^{*}}(b) = s(x^{*b})$
\setbeamertemplate{itemize items}[ball]

\framebox{
\item \textbf{Step 1} Select B independent bootstrap samples $x^{*1}$, $x^{*2}$,...  $x^{*B}$ each consisting of n data values drawn with replacement from $x$  
}
\end{itemize}
\end{frame}

答案1

\framebox在这里不起作用。它将框住短文本,而长文本将放在一行中,突出到边距中。除此之外,尝试使用框住项目标签\framebox{\item...}会导致您收到的错误。

您可以使用预先\parbox\item内容括起来:

\documentclass{beamer}

\begin{document}

\begin{frame}[t]{Bootstrap}
\begin{itemize}
\item Compute variability of parameter by means of resampling with replacement
\item Standard error necessary to compute prediction error 
\item Algorithm Efron and Tibshirani (1994) 
\item $\hat{\theta^{*}}(b) = s(x^{*b})$
\setbeamertemplate{itemize items}[ball]
%
\item \framebox{\parbox[t]{\dimexpr\linewidth-2\fboxsep-2\fboxrule\relax}{\textbf{Step 1} Select B independent bootstrap samples $x^{*1}$, $x^{*2}$,...  $x^{*B}$ each consisting of n data values drawn with replacement from $x$}%
}
\end{itemize}
\end{frame}

\end{document}

在此处输入图片描述

当然,如果你需要多次使用,你可以定义一个命令。例如,

\newcommand\FText[1]{%
  \framebox{\parbox[t]{\dimexpr\linewidth-2\fboxsep-2\fboxrule\relax}{#1}}%
}

进而

\item \FText{\textbf{Step 1} Select B independent bootstrap samples $x^{*1}$, $x^{*2}$,...  $x^{*B}$ each consisting of n data values drawn with replacement from $x$}

请注意,只是内容被装箱,而不是全部\item;否则,您将获得错误的项目标签对齐方式。

如果您还想附上物品标签,则还需要做一些额外的工作:

\documentclass{beamer}
\usepackage{tikzpagenodes}
\usetikzlibrary{tikzmark}

\newcounter{tmp}
\newcommand\FText[1]{%
\stepcounter{tmp}%
\tikzmark{start-\thetmp}#1\tikzmark{end-\thetmp}
\begin{tikzpicture}[remember picture,overlay]
\draw
  ([xshift=-15pt,yshift=2.3ex]pic cs:start-\thetmp) 
    rectangle 
  ([yshift=-1ex]current page text area.east|-{pic cs:end-\thetmp});
\end{tikzpicture}%
}

\begin{document}

\begin{frame}[t]{Bootstrap}
\begin{itemize}
\item Compute variability of parameter by means of resampling with replacement
\item Standard error necessary to compute prediction error 
\item Algorithm Efron and Tibshirani (1994) 
\item $\hat{\theta^{*}}(b) = s(x^{*b})$
\setbeamertemplate{itemize items}[ball]
%
\item \FText{\textbf{Step 1} Select B independent bootstrap samples $x^{*1}$, $x^{*2}$,...  $x^{*B}$ each consisting of n data values drawn with replacement from $x$}

\end{itemize}
\end{frame}

\end{document}

在此处输入图片描述

该代码需要运行两到三次才能稳定下来。

相关内容