4

I am using vspace for producing a white space for people to write on between blocks of text. When the vspace happens to be at the end of a page, the next block of text will start at the top of the next page, while it is desired that in such case, the "remainder" of the vspace should spill the next page. How can I change the code to achieve that? Thanks.

\documentclass{article}
\usepackage{lipsum}

\begin{document}

\lipsum[2-5] % towards the end of the page
\vspace{15cm} % 15 cm of white space desired
\lipsum[2-3] % appears at the top of the next page

\end{document}
4

This might serve your need. \xvspace{}{} allows you to specify a number #1 of vspace increments to execute, of units #2. By inserting a \par between each increment and leaving vertical mode, the final elements of the loop are executed on the subsequent page.

I have to subtract off \baselineskip and \parskip with each loop cycle, to counteract the effect of the inserted \pars.

In the MWE, I print a rule of 5cm height, as a reference, later, I insert \xvspace{10}{cm}.

\documentclass{article}
\usepackage[pass,showframe]{geometry}
\usepackage{lipsum}
\usepackage{forloop}
\newcounter{vspaceinc}
\newcommand\xvspace[2]{\par\leavevmode%
  \forloop{vspaceinc}{0}{\thevspaceinc<#1}{%
  \vspace{\dimexpr1#2-\baselineskip-\parskip}\leavevmode\par}%
}
\begin{document}

\rule{1pt}{5cm}
\lipsum[2-3] % towards the end of the page
\xvspace{10}{cm} % 15 cm of white space desired
\lipsum[2-3] % appears at the top of the next page

\end{document}

enter image description here

4

You can use a needspace-like approach; that is, measure the space left on the page and condition on inserting a break plus an additional \vspace* at the top of the next page, or just inserting a regular \vspace. \insertgap{<len>} in the minimal example below does that:

enter image description here

\documentclass{article}

\usepackage{lipsum}

\newlength{\gapinsert}
\newcommand{\insertgap}[1]{%
  \par
  \ifdim\dimexpr\pagegoal-\pagetotal<#1
    % Capture space remaining after page break
    \setlength{\gapinsert}{\dimexpr#1-\pagegoal+\pagetotal}%
    \pagebreak% Insert page break
    \vspace*{\gapinsert}% Insert additional/remaining gap; https://tex.stackexchange.com/q/33370/5764
  \else
    % Enough space available on page
    \vspace{#1}% Insert regular vspace
  \fi
}

\begin{document}

\lipsum[1-4]

\vspace{8cm}

\lipsum[5]

\pagebreak

\lipsum[1-4]

\insertgap{8cm}

\lipsum[5]

\end{document}
2

The \addblockspace{..} command adds white vertical space as needed. If that space is larger than what is already available on the page, it fills the page and add the rest on the next page using \vspace*{}

I added a grid to help measure the spaces on both pages and to test the code.

15cm

a15

5cm

b5

3cm c3

\documentclass{article}

\usepackage{lipsum}

% ******************************** needed
\usepackage{calc}
\usepackage{ifthen}

\newlength{\spacetobottom}
\newlength{\spacetoadd}

\newcommand{\addblockspace}[1]{% add blank space as needed
\setlength{\spacetobottom}{\textheight-\pagetotal}      % space left on the page
\setlength{\spacetoadd}{#1} % total space needed

\ifthenelse{\spacetobottom > \spacetoadd}%
{\parbox[t][\spacetoadd]{0pt}{}}%% stay in the first page
{\vspace{\fill}\newpage\vbox{\vspace*{#1 -\spacetobottom}}} % start a newpage and add the difference
                }
% ********************************          

% ----------------------------------*only to measure the space
\usepackage{showframe}
\newcommand{\gridpaper}{% draw a grid spaced 1em
    \begin{tikzpicture}
        \draw[line width=.4pt,draw=black!30] (0,0) grid[step=1cm] (\paperwidth,\paperheight);
    \end{tikzpicture}%
}
\usepackage{tikz}
\usepackage{background}
\backgroundsetup{%
    angle=0,
    contents=\gridpaper,
    scale=1,
}
% -------------------------------------*

\begin{document}
    
\lipsum[2-5] % towards the end of the page  

\addblockspace{15cm} % 15cm of blank space needed <<<<<<<<<<<
        
2. \lipsum[2-3] % 
    
\end{document}

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.