我正在为我的班级写一份考试。问题文件需要在每个问题后面有一个空框,而解决方案文件应该有解决方案(最好是不同的颜色)。我从以下网址获取了执行此操作的代码这里。
不幸的是,这只适用于那些只包含文本/数学的解决方案。我也有数字,这会引发“浮点数丢失”错误。这是 MWE。
\documentclass{article}
\usepackage{etex}
\usepackage{pdfsync}
\usepackage{amsfonts, amsmath, amssymb, amsthm, thmtools}
\usepackage{hyperref}
\usepackage[dvipsnames,svgnames,x11names,hyperref]{xcolor}
\usepackage{subcaption}
\usepackage{pgfplots}
%%%%%%%%%%%%%%%%%%%%%%
% STUFF FOR SOLUTION ENVIRONMENT
\usepackage{ifthen}
\newenvironment{solution}[1]{%
\ifthenelse{\isundefined{\teacher}}{%
\fbox{\begin{minipage}{\linewidth}\hfill\vspace*{#1}\end{minipage}}%
}{}%
\newbox\tempbox%
\begin{lrbox}{\tempbox}\begin{minipage}{\linewidth}%
}{%
\end{minipage}\end{lrbox}%
\ifthenelse{\not\isundefined{\teacher}}{%
\medskip%
\fbox{\usebox{\tempbox}}%
\medskip%
}{}%
}
\def\teacher{true} %comment this out for empty box (in student's version)
%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{enumerate}
\item This is the first problem on the test. \\
\begin{solution}{5cm}
This is the first solution.
\end{solution}
\item This is the second problem. \\
\begin{solution}{5cm}
This is the second solutiuon.
%%%%%%%%%%%%%%%%%%%%
% COMMENT OUT FIGURE BELOW TO SEE IT WORK
\begin{figure}[h]
\centering
\begin{tikzpicture}
\begin{axis} [
height=5cm, width=7cm, xlabel={$t$}, ylabel={$x(t)$},
xmin=-4, xmax=4, ymin=-1.5, ymax=1.5, no markers,
xtick={-2.5, -.5, .5, 2.5}, ytick={1, -1},
axis lines=middle
]
\addplot[thick, black] coordinates {(-1, 0) (0, 1) (1, 0)};
\end{axis}
\end{tikzpicture}
\caption{Output signal for Problem 3a}\label{fig:samplefig}
\end{figure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{solution}
\end{enumerate}
\end{document}
答案1
figure
不幸的是,如何在环境中使用并不明显minipage
,请参阅如何在小页面中使用图形?。
如果您可以避免图形环境,您可以简单地这样做:
\documentclass{article}
\usepackage{etex}
\usepackage{pdfsync}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage[dvipsnames,svgnames,x11names,hyperref]{xcolor}
\usepackage{amssymb}
\usepackage{amsthm, thmtools}
\usepackage{subcaption}
\usepackage{pgfplots}
a%%%%%%%%%%%%%%%%%%%%%%
% STUFF FOR SOLUTION ENVIRONMENT
\usepackage{ifthen}
\newenvironment{solution}[1]{%
\ifthenelse{\isundefined{\teacher}}{%
\fbox{\begin{minipage}{\linewidth}\hfill\vspace*{#1}\end{minipage}}%
}{}%
\newbox\tempbox%
\begin{lrbox}{\tempbox}\begin{minipage}{\linewidth}%
}{%
\end{minipage}\end{lrbox}%
\ifthenelse{\not\isundefined{\teacher}}{%
\medskip%
\fbox{\usebox{\tempbox}}%
\medskip%
}{}%
}
\def\teacher{true} %comment this out for empty box
%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{enumerate}
\item This is the first problem on the test. \\
\begin{solution}{5cm}
This is the first solution.
\end{solution}
\item This is the second problem. \\
\begin{solution}{5cm}
This is the second solutiuon.
%%%%%%%%%%%%%%%%%%%%
% COMMENT OUT FIGURE BELOW TO SEE IT WORK
\begin{center}
\begin{tikzpicture}
\begin{axis} [
height=5cm, width=7cm, xlabel={$t$}, ylabel={$x(t)$},
xmin=-4, xmax=4, ymin=-1.5, ymax=1.5, no markers,
xtick={-2.5, -.5, .5, 2.5}, ytick={1, -1},
axis lines=middle
]
\addplot[thick, black] coordinates {(-1, 0) (0, 1) (1, 0)};
\end{axis}
\end{tikzpicture}
{Output signal for Problem 3a}\label{fig:samplefig}
\end{center}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{solution}
\end{enumerate}
\end{document}