6

I am trying to include some vertical spacing between two lines. In the example below, the space between questions 2 and 3 should have been the same as between 1 and 2. However, as you can see in this screenshot; the result is not the desired one.

The code used to produce that document is the following. I would welcome any additional comments on improving this code as I am really new to this.

\documentclass[letterpaper,12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{amstext}
\usepackage{fancyhdr}
\usepackage{graphicx}
\pagestyle{fancy}

\chead{}
\definecolor{cbseblue}{HTML}{7388c7}
\definecolor{cbsegreen}{HTML}{bcd490}
\renewcommand{\headrule}{{\color{cbseblue} \hrule width\headwidth height\headrulewidth \vskip-\headrulewidth}}
\renewcommand{\footrule}{{\color{cbseblue}\vskip-\footruleskip\vskip-\footrulewidth\hrule width\headwidth height\footrulewidth\vskip\footruleskip}}

\lfoot{\color{cbseblue}\textit{June 5, 2012 - 14:04:23}}
\cfoot{\color{cbseblue}\thepage}

\fancyhfoffset[R]{0in}
\renewcommand{\headrulewidth}{1.2pt}
\renewcommand{\footrulewidth}{1.2pt}
\renewcommand{\headsep}{26pt}
\renewcommand{\footruleskip}{0.1in}

\setlength{\parindent}{0pt}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \oddsidemargin  -0.5in
    \evensidemargin  0.0in
    \textwidth       7.5in
    \headheight      0.5in
    \topmargin      -0.7in
    \textheight      8.9in
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\vspace*{-10pt}
\begin{center}
\Large { \bfseries Model Exam 3 }
\\[46pt]
\end{center} 
\textbf{1.} Differentiate the function $\sin \left( {{x^2} + 5} \right)$ w.r.t. $x$ $\frac{{dy}}{{dx}} = 2x\cos \left( {{x^2} + 1} \right)$ {\color{cbseblue}\textit{[1 pts]}}
\\[440pt]
\textbf{2.} Differentiate $y = \sin \left( {{x^2} + 5} \right)$ w.r.t. $x y = \sin \left( {{x^2} + 5} \right) \frac{d}{{dx}}\left( y \right) = \frac{d}{{dx}}\sin \left( {{x^2} + 5} \right)$ {\color{cbseblue}\textit{[1 pts]}}
\\[440pt]
\textbf{3.} Find the values of  $a,\;b,\;c$$\;$and$\;$$d$ from the equation: $\left[ {\begin{array}{*{20}{c}}
  {\;\;\;\;a - b}&{2a + c} \\ 
  {2a - b}&{3c + d} 
\end{array}} \right] = \left[ {\begin{array}{*{20}{c}}
  { - 1}&5 \\ 
  \;\;\;\;0&{13} 
\end{array}} \right]$ {\color{cbseblue}\textit{[1 pts]}}
\\[220pt]
\end{document}

Another thing to take into consideration is that the questions of this exam come from a database, where the user who entered them also assigned a coefficient for the space to be reserved for the solution (let's say from 1, 2, 3, 4, or 5). So when building the pdf, I am first creating the tex file programatically by having a loop as below:

    //php code
    foreach($questions as $question) {
         echo $question['content']."\n";
         $space = 110 * $question['coefficient'];
         echo '\\\['.$space.'pt]."\n";
    }
2
  • there was a similar question that i can't find now. one of the answers suggested shipping out the desired number of blank lines one by one (perhaps as \vspace*{1\baselineskip} using the * form so they don't get gobbled at the top of a page), and letting (la)tex take its accustomed course. Commented Aug 24, 2012 at 13:42
  • This may be that similar question: tex.stackexchange.com/questions/67311/… Commented Jun 8, 2016 at 14:55

1 Answer 1

4

The vertical space is gobbled at the start of the page, even when introducing a page break. I would insert the amount of vertical space manually between the respective questions (similar to what you did, just differently) and re-insert it after a page break. Perhaps something like this

Question 1
2/3 vertical gap on page
Question 2
1/3 vertical gap on page
--- page break ---
1/3 vertical gap on page
Question 3
2/3 vertical gap on page

Here's some code that generates that:

enter image description here

% ...document preamble
\begin{document}
\vspace*{-10pt}
\begin{center}
  \Large\bfseries Model Exam 3
\end{center}

\bigskip\bigskip

\textbf{1.} Differentiate the function $\sin \left( x^2 + 5 \right)$ w.r.t.\ 
  $x$ $\frac{\mathrm{d}y}{\mathrm{d}x} = 2x\cos \left( x^2 + 1 \right)$ 
  {\color{cbseblue}\textit{[1 pts]}}

\vfill \vfill

\textbf{2.} Differentiate $y = \sin \left( x^2 + 5 \right)$ w.r.t.\ 
  $x y = \sin \left( x^2 + 5 \right) \frac{\mathrm{d}}{\mathrm{d}x}\left( y \right) = 
    \frac{\mathrm{d}}{\mathrm{d}x}\sin \left( x^2 + 5 \right)$ 
  {\color{cbseblue}\textit{[1 pts]}}

\vfill

\newpage

\null\vfill

\textbf{3.} Find the values of  $a,\;b,\;c$ and~$d$ from the equation: $\left[ \begin{array}{rr}
     a - b & 2a + c \\ 
    2a - b & 3c + d 
  \end{array} \right] = \left[ \begin{array}{rr}
    -1 &  5 \\ 
     0 & 13 
  \end{array} \right]$ 
  {\color{cbseblue}\textit{[1 pts]}}

\vfill \vfill
\end{document}​
1
  • Werner, your code looks much shorter and cleaner. Thank you for that. Regarding the space, yes that is exactly what I was looking for as output. The only problem here is that I didn't describe the whole situation. I updated my question by adding the last part to it. So the problem is that since everything is being created programmatically, I would not know when a question is located at the bottom of the page so that I would insert that \newpage and \null\vfill command. Am I being clear ?!
    – Arber
    Commented Aug 24, 2012 at 13:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .