我想自动生成可以填充的重复元素,并将它们放在一起

我想自动生成可以填充的重复元素,并将它们放在一起

我希望自动生成一个“使用以下内容”,后面跟着一个\fbox\parbox我可以用文本、图形等进行填充。我通常手动执行此操作,但想创建(这叫做自定义环境吗?)一个自动的环境。

也许是类似的东西\usefollow{#1}?实现此目的的最佳方法是什么?

我已经包含了每次我想要短语“使用以下内容回答下一个问题”后跟框中的信息时要做的事情。有没有办法自动重复?我把它放在 minipages 中的原因是为了防止“使用以下内容”与 ie 被\fbox分页符分开。

\documentclass[11pt]{exam}
\usepackage{mathtools}
\usepackage{xcolor}
\usepackage{amssymb}
\usepackage{pifont}
\usepackage{tikz}
\usetikzlibrary{math}
\usepackage[font=scriptsize,hypcap=false]{caption}

%% make this a code. 
\newcommand\usefollow{\begin{center}\textit{Use the following information to answer the next question}\end{center}\vspace{-5pt}}

\printanswers
\graphicspath{ {./dir1/} }
\usepackage{hyperref}

\begin{document}
%% I used a minipage to keep it together.  
\begin{minipage}[t]{\linewidth}
\vspace{0pt}
\usefollow{}%%%This just creates the "use the following.."

\fbox{\parbox{\linewidth}{
Consider the following equation or graph.%%inside I could put anything, graph, minipage etc.  
}}
\end{minipage}%
\hfill\\
%% I want it all in one.

\end{document}

答案1

您可以使用它lrbox来存储环境的内容并在稍后打印。

采取预防措施,以便使用 时框上方的文本不会在分页符处分离\\*

\documentclass[11pt]{exam}
\usepackage{mathtools}
\usepackage{xcolor}
\usepackage{amssymb}
\usepackage{pifont}
\usepackage{tikz}
\usetikzlibrary{math}
\usepackage[font=scriptsize,hypcap=false]{caption}
\usepackage{hyperref}

\newsavebox{\usefollowbox}
\newenvironment{usefollow}
 {%
  \par % be sure to be between paragraphs
  \addvspace{\topsep}% some vertical space
  \begin{lrbox}{\usefollowbox}
  \begin{minipage}{\dimexpr\linewidth-2\fboxsep-2\fboxrule}
 }
 {%
  \end{minipage}
  \end{lrbox}
  \begingroup % to confine the effect of \centering
  \centering\itshape 
  Use the following information to answer the next question\\*[3pt]% no page break
  \fbox{\usebox{\usefollowbox}}\par
  \endgroup
  \addvspace{\topsep}
}

\printanswers
\graphicspath{ {./dir1/} }

\begin{document}

\begin{usefollow}
Consider the following equation or graph.
\[
a^2+b^2=c^2
\]
\begin{center}
\includegraphics[width=0.5\textwidth]{example-image}
\end{center}
and finish up.
\end{usefollow}

\end{document}

在此处输入图片描述

答案2

您可以使用该environ包来定义一个环境,收集您的提示并将其打包到您周围的命令中。

\usepackage{environ}
\NewEnviron{hint}{%
  \begin{center}\itshape
    Use the following information to answer the next question
  \end{center}\vspace{-5pt}
  \fbox{\parbox{\dimexpr\linewidth-2\fboxsep-2\fboxrule}{\BODY}}%
}

在此处输入图片描述

\documentclass[11pt]{exam}
\usepackage{environ}
\NewEnviron{hint}{%
  \begin{center}\itshape
    Use the following information to answer the next question
  \end{center}\vspace{-5pt}
  \fbox{\parbox{\dimexpr\linewidth-2\fboxsep-2\fboxrule}{\BODY}}%
}

\begin{document}
\begin{hint}
Consider the following equation or graph.%%inside I could put anything, graph, minipage etc.  
\end{hint}
\end{document}

相关内容