Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm putting a template together and I have created a custom command which I'm going to use to set specific margins on the text passed to its argument and a few more formatting things, like this:

\newcommand{\mytextbox}[1] {#1}

I want it so text passed to this command splits across new pages nicely but before the new page begins, I want to print a new separate line saying "Continued on next page" and on the next page, print a line above the remaining text saying "Continued from previous page".

So for example if I do this near the bottom of a page:


It will print a few lines before flowing to the next page, but have my custom titles at the bottom and top of the next page, like this:

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae,
**Continued on next page**


**Continued from previous page**
Curabitur dictum gravida mauris. Nam arcu libero,
nonummy eget, consectetuer id, vulputate a, magna. Donec
vehicula augue eu neque. Pellentesque habitant morbi tristique
senectus et netus et malesuada fames ac turpis egestas. Mauris
ut leo.

I've been banging my head against the wall trying to figure out a way to do this. Nothing seems to work for me. My best guess is finding something in TeX that controls when it wraps the lines, checking if its the last line of the page and inserting a \newpage command in to the text but I haven't found a way to do this and it seems a bit convoluted. I don't care whether mytextbox is a command or environment as long as it behaves as above.

share|improve this question
An suggestion is given in the post: tex.stackexchange.com/questions/24106/… –  Marco Daniel Oct 16 '11 at 10:32
Welcome to TeX.sx! A tip: You can use backticks ` to mark your inline code as I did in my edit. –  doncherry Oct 16 '11 at 10:35
Are you using headers and footers by fancyhdr? If not, I could attempt to write up a solution using that package. –  doncherry Oct 16 '11 at 10:36
@doncherry I'm not using fancyhdr but I'll consider anything as long as the titles are directly below and above the text as in the example, and only occur for mytextbox items. –  Sophie Welles Oct 16 '11 at 10:41

1 Answer 1

up vote 3 down vote accepted

Here is a solution, assuming you generally want the plain page style with only the page number at the bottom. The only thing that I couldn't fix is the space between the "continued" lines and the actual text. Suggestions on that are welcome! I added the italics, you can just remove that if you don't like it. This code will add the "continued" texts no matter if the text you pass to \mytextbox actually breaks onto the next page or not.

Once you start messing with the page layout, further adaptions might be necessary.

\documentclass{article}% This only works for one-side documents! For two-side documents, more meddling with oddfoot and evenfoot is necessary.

\usepackage{lipsum}% filler text
\usepackage{afterpage}% for commands to be executed after the page
\usepackage{fancyhdr}% for direct access to headers and footers
\usepackage{array}% improved tables

% Define new page style "contbottom"
    \renewcommand{\@oddhead}{}% empty header
        \begin{tabular}{@{}>{\raggedright}p{.4\linewidth}@{}>{\centering}p{.2\linewidth}@{}>{\raggedleft}p{.4\linewidth}@{}}% table to get spacing correct
    \textit{**Continued on next page**} &% = footer left
    ~\\\thepage &% = footer center, put empty line above page number
    % = footer right

% Define new page style "conttop"
    \renewcommand{\@oddhead}{\textit{**Continued from previous page**}\hfill}% header
    \renewcommand{\@oddfoot}{\begin{tabular}{@{}>{\raggedright}p{.4\linewidth}@{}>{\centering}p{.2\linewidth}@{}>{\raggedleft}p{.4\linewidth}@{}}% table to get spacing correct
    &% = footer left
    ~\\\thepage &% = footer center, empty line as well so all pages look the same
    % = footer right

% Put page number one line lower for normal pages

% Define command \mytextbox
    \thispagestyle{contbottom}% page style contbottom for this page
    \afterpage{\thispagestyle{conttop}}% page style conttop for the next page
    #1% print text






pages 1 and 2 pages 3 and 4

share|improve this answer
Thank you, this is looking promising. –  Sophie Welles Oct 16 '11 at 12:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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