我正在使用下面的代码创建一个问题及其解决方案。如果我将ans
命令(我创建的)设置为 true,则将打印解决方案,如果我将其设置ans
为 false,则不会打印解决方案。
我担心的是,当我设置ans
为 false 时,我需要有垂直空白。我希望垂直空白占据与解决方案相同的垂直空间,即当我使用时\null\vspace{4cm}
,我希望这个数字(我手动设置的)基于解决方案文本的实际大小。
以下是代码:
\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{datetime}
%-----------------------------------------------------------------------------------------
% Print Answers
%-----------------------------------------------------------------------------------------
\newboolean{ans}
\newcommand{\sol}{true} % set this to false if you don't solution to be printed
\newcommand{\Ans}{{\color{blue}\textbf{Ans:}} }
\newcommand{\Sol}{{\color{blue}\textbf{\vskip0.001inSolution:\vskip0.05in}}}
\newcommand{\solspace}{\Sol \newpage}
\newtheorem{exm}{Example}[section]
%-----------------------------------------------------------------------------------------
% Set the Margins, Header and Footer
%-----------------------------------------------------------------------------------------
\usepackage[lastpage,user]{zref}
\usepackage{fancyvrb,fancyhdr}
\VerbatimFootnotes % Required, otherwise verbatim does not work in footnotes!
%\pagestyle{fancy}
\renewcommand{\headrulewidth}{0.4pt} % Add line after header
\renewcommand{\footrulewidth}{0in} % no line added before footer
\renewcommand{\thefootnote}{\fnsymbol{footnote}}
\textheight = 700pt % length of body text
%\textwidth = 500pt
\marginparwidth = 2in
\headsep = 0.2in
\voffset = -0.4in
\headheight = 15pt
\pagestyle{fancyplain}
\fancyhf{}
\lhead{\fancyplain{}{Mr.Stat}} % Course number on the left on 2nd page
\chead{\fancyplain{}{\emph{MLR}}} % Course name in the center on 2nd page
\rhead{\fancyplain{}{Class2}} % date of the course on 2nd page
\fancyfoot[L]{{\color{red}\copyright~~\the\year}}
\fancyfoot[R]{\small\hspace{5pt}{\color{red}\emph{Page \thepage\ of \zpageref{LastPage}}}}
\thispagestyle{plain} % If this is enable the header will not appear
%===========================================================================================
% Start document
%============================================================================================
\begin{document}
\noindent
%======================================================================================================================
\section{Introduction}
Assuming that $E(e_i)= 0,$ the response function for regression model is:
\[
E(Y_i) = \beta_0+\beta_1X_{i1}+\cdots+\beta_kX_{ik}
\]
This response function is a hyperplane, which is a plane in more than two dimensions. It is no longer possible to picture this response surface.
%------------------- Example 7.1 ----------------------
\begin{exm}
Back to the example 1 find the 90\% CI for the mean response at $X_h= \begin{pmatrix}1\\6.5\\0.35\end{pmatrix}$
%****************************** Solution ********************************
\setboolean{ans}{\sol}
\ifthenelse{\boolean{ans}}{\Sol
The fitted value at $X_h$ is
\[
Y_h = X'_h\beta = \begin{pmatrix}1,&6.5,&0.35\end{pmatrix}\begin{pmatrix}0.6666667\\1.3166667\\-8.0000000\end{pmatrix}= 0.667 + 1.317(6.5) -8(0.35) = 6.425
\]
and
$$
SSE =Y'Y - \beta'X'Y = 396.57- 395.225 =1.345 \mbox{ then } MSE= 0.1494.
$$
The 90\% CI for $E(Y_h)$ is
\[
\begin{array}{lcl}
E(Y_h)&\in& \left(6.425 \pm 1.812\sqrt{(0.1494)(0.18125)}\right)= (6.425 \pm 0.117)= (6.308371, 6.541629)
\end{array}
\]
}
{
\Sol
\null\vspace{4cm}
}
\end{exm}
\end{document}