# Changing top, bottom, left & right margins on the fly

I’m trying to find a way of being able to modify all of the margins of a page whenever I want to and as many times as I want to on a single page in order to be able to put text very easily where I want on a page.

I have thought of using the geometry package and using

 \newgeometry{left=6.75cm, right=1cm, top=1cm, bottom=1cm}
%…
\restoregeometry


but unfortunately this only works for whole pages, so I can only change the margins once per page (and then they are valid for the whole page without having the possibility of changing them again).

I found the following script on the internet which enables users to change margins on the fly, just as I want to. The code below works fine and enables me to change the left and right margins of my page as many times as I want to, but unfortunately, it doesn’t give me the option of changing the top and bottom margins.

% placed before \begin{document}

\newenvironment{changemargin}[2]{%
\begin{list}{}{%
\setlength{\leftmargin}{#1}%
\setlength{\rightmargin}{#2}%
}%
\item[]}
{\end{list}}

% And then inside the document, whenever I want to use
% the command to change the margins on the current page

\begin{changemargin}{1.9875cm}{-3.7625cm}
% this means the left margin increases by 1.9875cm compared
% to the default left margin (4.7625cm) (so left margin=6.75cm here)
% and the right margin decreases by 3.7625cm (so right margin=1cm)

% ... (text or pictures in new environment)

\end{changemargin}


For this reason, I tried to adapt the code above and came up with the code below:

% placed before \begin{document}
\newenvironment{changemargin}[3]{%
\begin{list}{}{%
\setlength{\leftmargin}{#1}%
\setlength{\rightmargin}{#2}%
\setlength{\topmargin}{#3}%
}%
\item[]}
{\end{list}}

% And then to use the command:
\begin{changemargin}{1.9875cm}{-3.7625cm}{1cm}
% ...
\end{changemargin}


It compiles and still changes the left and right margins but the top margin remains unchanged. (I haven’t yet tried to change the bottom margin).

Can anyone help me get this code to work completely, and enable me to modify the left, right, top and bottom margins of a page? Thanks.

-
@Percy If you want to place text arbitrarily on a page, I suggest you see if the package textpos can satisfy your needs. The command \enlargethispage{<a dimension>} enlarge the page with a given number or lines, points, centimetres etc. –  Sveinung Aug 26 '12 at 13:46
Did you try to use minipage? –  Sigur Aug 26 '12 at 14:17

You can use a combination of geometry (to change the top and bottom margings) and the adjustwidth environment provided by the changepage package (this uses internally a list and it's similar to your changemargin environment):

\documentclass{article}
\usepackage[paperheight=14cm]{geometry}
\usepackage{changepage}
\usepackage{lipsum}

\begin{document}
\lipsum[1-3]
\newpage
\newgeometry{top=0.5cm, bottom=0.5cm}
\lipsum[4]
\lipsum[1]
\lipsum[3]
\lipsum[4]
\newpage
\restoregeometry
\lipsum[1-3]
\newpage
\newgeometry{top=2.5cm, bottom=2.5cm}
\lipsum[4]
\lipsum[4]
\lipsum[3]

\end{document}


I strongly suggest you, as a personal opinion, not to do this.

-
Hear hear!!.... –  percusse Aug 26 '12 at 15:20

Just for the sake of completeness: with a KOMA class you can produce the same weird results with KOMA-Scripts own addmargin environment.

I took the liberty to take Gonzalo Medina's example and adjust it for scrartcl:

\documentclass{scrartcl}
\usepackage[paperheight=18cm]{geometry}
\usepackage{lipsum}

\begin{document}
\lipsum[1-3]
\newpage
\newgeometry{top=0.5cm, bottom=0.5cm}
\lipsum[4]
\lipsum[1]
\lipsum[3]
\lipsum[4]
\newpage
\restoregeometry
\lipsum[1-3]
\newpage
\newgeometry{top=2.5cm, bottom=2.5cm}