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.


\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}}



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

\Large { \bfseries Model Exam 3 }
\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]}}
\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]}}
\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 \\ 
\end{array}} \right]$ {\color{cbseblue}\textit{[1 pts]}}

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";
  • 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. Aug 24, 2012 at 13:42
  • This may be that similar question: tex.stackexchange.com/questions/67311/… Jun 8, 2016 at 14:55

1 Answer 1


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
  \Large\bfseries Model Exam 3


\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]}}




\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
  • 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
    Aug 24, 2012 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.