自动缩小文本大小以适合框架内

自动缩小文本大小以适合框架内

我需要一个代码(所以,创建了它:P)来减小字体大小以使其适合框架(或)内minipageframe并且不让它从那里溢出到页脚区域。

假设我们有一个简单的beamer-frame有两个minipage如下所示的 s ,我们不想让文本从那里溢出到页脚:

\documentclass[20pt]{beamer}
\usetheme{Warsaw}
\begin{document}
\section{test section}
\begin{frame}
\begin{minipage}{0.45\textwidth}
%\begin{autotext}%Need to define this to do nothing if text is not too tall
 This is a random text that will be added in this first column of the presentation under a bold title as seen here. The text will automatically reduce the font size to fit the page's height if it is too large\ldots
%\end{autotext}
\end{minipage}\hfill
\begin{minipage}{0.45\textwidth}
%\begin{autotext}%Need to define this to reduce the font size as far as needed in order to not let the text overflow
This is a random bigger text that in the previous column that will be added in this second column of the presentation under a bold title as seen here. The text this time will really reduce the font size to fit the page's height because it is  too large\ldots To make this text to large I have to add some more text like doing here and so, you don't really have to read this random text from this place and after\ldots It is just random text to make the text really tall. But this is difficult as I just realized and I have to add more and more text in order to see this effect here and to let the size be reduced into \texttt{\textbackslash small} size. This is the final words I had to add because befor this lines I can't see this resizing.
%\end{autotext}
\end{minipage}
\end{frame}
\end{document}

我怎样才能创建这个自动化环境?

答案1

fitting一个选项是使用库和包将内容放入合适的框中tcolorbox(参见手册第 21 章tcolorbox)。有几种合适的算法可用于将文本适合框的指定高度和宽度。

\documentclass[20pt]{beamer}
\usetheme{Warsaw}
\usepackage[fitting]{tcolorbox}
\newcommand*{\mytext}{This is a random text that will be added in this first 
                      column of the presentation under a bold title as seen here. 
                      The text will automatically reduce the font size to fit the 
                      page's height if it is too large.}
\newtcboxfit{\mybox}{height=6.5cm,boxsep=0mm,top=2mm,bottom=2mm,left=2mm,right=2mm,
                     nobeforeafter,width=\linewidth}
\begin{document}
\section{test section}
\begin{frame}[t]
  \frametitle{Outline}
  \begin{columns}[totalwidth=\textwidth]
    \begin{column}[t]{0.48\textwidth}
       \mybox{\mytext\ \ldots}
    \end{column}
%
    \begin{column}{.04\textwidth}
    \end{column}
%
    \begin{column}[t]{0.48\textwidth}
      \mybox{\mytext\ \ldots \mytext\ \ldots \mytext\ \ldots \mytext\ \ldots}
  \end{column}
  \end{columns}
\end{frame}
\end{document}

在此处输入图片描述

答案2

通过使用environ包和pgffor(只是为了简化\loop):

\documentclass[12pt]{beamer}
\usetheme{Warsaw}
\usepackage{environ}
\usepackage{pgffor}

\newcounter{boxCounter}
\newsavebox{\boxA}
\newsavebox{\boxB}
\newsavebox{\boxC}
\newsavebox{\boxD}


\newlength{\availafter}

\NewEnviron{autotext}[1][0.5cm]
{\setcounter{boxCounter}{0}\foreach \mysize in {\normalsize,\small,\footnotesize,\scriptsize}{\stepcounter{boxCounter}\expandafter\savebox\csname box\Alph{boxCounter}\endcsname{\vbox{\mysize\BODY}}\setlength{\availafter}{\dimexpr\textheight-\expandafter\ht\csname box\Alph{boxCounter}\endcsname-\pagetotal\relax}\ifdim\availafter>#1\expandafter\usebox\csname box\Alph{boxCounter}\endcsname\breakforeach\fi}}


\begin{document}
\section{test section}
\begin{frame}
\begin{minipage}{0.45\textwidth}
\begin{autotext}%Need to define this to do nothing if text is not too tall
 This is a random text that will be added in this first column of the presentation under a bold title as seen here. The text will automatically reduce the font size to fit the page's height if it is too large\ldots
\end{autotext}
\end{minipage}\hfill
\begin{minipage}{0.45\textwidth}
\begin{autotext} %Need to define this to reduce the font size as far as needed in order to not let the text overflow
This is a random bigger text that in the previous column that will be added in this second column of the presentation under a bold title as seen here. The text this time will really reduce the font size to fit the page's height because it is  too large\ldots To make this text to large I have to add some more text like doing here and so, you don't really have to read this random text from this place and after\ldots It is just random text to make the text really tall. But this is difficult as I just realoized and I have to add more and more text in order to see this effect here and to let the size be reduced into \texttt{\textbackslash small} size. Thi is the final words I had to add because befor this lines I can't see this resizing.
\end{autotext}
\end{minipage}
\end{frame}
\end{document}

结果是:

在此处输入图片描述

PS:另请参阅@Ross 的回答,tcolorbox而不仅仅是。

相关内容