21

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.

2
  • @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, 2012 at 13:46
  • Did you try to use minipage?
    – Sigur
    Aug 26, 2012 at 14:17

2 Answers 2

16

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}
\begin{adjustwidth}{-2cm}{-1cm}
\lipsum[4]
\end{adjustwidth}
\lipsum[1]
\begin{adjustwidth}{1cm}{2cm}
\lipsum[3]
\end{adjustwidth}
\lipsum[4]
\newpage
\restoregeometry
\lipsum[1-3]
\newpage
\newgeometry{top=2.5cm, bottom=2.5cm}
\begin{adjustwidth}{2cm}{2cm}
\lipsum[4]
\end{adjustwidth}
\lipsum[4]
\begin{adjustwidth}{3cm}{-3cm}
\lipsum[3]
\end{adjustwidth}

\end{document}

enter image description here

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

3
  • Thanks for the nice answer, what is the purposeo \usepackage{lipsum} and \lipsum here?
    – wonderich
    Nov 23, 2018 at 18:05
  • The lipsum package is just used to create filler text. In your document, you won't need the package, and you'll replace all instances of \lipsum with your own copy.
    – Merchako
    Jun 11, 2020 at 17:33
  • @Gonzalo Medina would you plese shed a light to do margin in order to perform the same affect of crop PDF or another format else: tex.stackexchange.com/questions/577875/… Jan 9, 2021 at 9:34
1

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}
\begin{addmargin}[-2cm]{-1cm}
\lipsum[4]
\end{addmargin}
\lipsum[1]
\begin{addmargin}[1cm]{2cm}
\lipsum[3]
\end{addmargin}
\lipsum[4]
\newpage
\restoregeometry
\lipsum[1-3]
\newpage
\newgeometry{top=2.5cm, bottom=2.5cm}
\begin{addmargin}[2cm]{2cm}
\lipsum[4]
\end{addmargin}
\lipsum[4]
\begin{addmargin}[3cm]{-3cm}
\lipsum[3]
\end{addmargin}

\end{document}

Since the output looks nearly the same I don't provide a picture.

You must log in to answer this question.

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