141

Sometimes the margins need to be changed for a particular page, paragraph, or other section of text. For example, if I'm writing a letter and want the left margin to be almost at the right side of the page for the four lines of my address, or if I am combining prose with poetry and want the poems to be indented relative to the rest of the work.

What is the best way to change both left and right margins on the fly?

lockstep
  • 250,273
Michael Underwood
  • 21,356
  • 13
  • 52
  • 41

7 Answers7

124

Here is how you can do it. Put the following in the preamble (before \begin{document})

\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1}\item[]}
\let\endchangemargin=\endlist 

then in the text you can use

\begin{changemargin}{<arg>}{<arg>} 
\end{changemargin} 

where <arg> is the distance you want to include on the margin (the first one defines the right-hand side margin, and the second defines the left-hand side one).

So, for example, to add 0.5 cm to the margins on either side, you would have:

\begin{changemargin}{0.5cm}{0.5cm} 
%your text here  
\end{changemargin}

This is exactly how the command

\begin{quote}
\end{quote}

is defined, but with the set to 1cm. The command quote can be used without having to load any packages, by the way.

lockstep
  • 250,273
Vivi
  • 26,953
  • 31
  • 77
  • 79
  • Thanks Vivi. I take it you mean "where is the distance...", right? Are there any advantages to this version over using a package such as changepage? – Michael Underwood Jul 30 '10 at 22:32
  • @Michael: Sorry, because of html the was not showing (though it was written). About the advantages over changepage, I really don't know. I have never used changepage and didn't even know it existed. I guess I need to try it out :) Have you tried the package yet? Is it good and straightforward? – Vivi Jul 30 '10 at 22:39
  • I haven't used it for a specific purpose yet, but was able to figure out how to do what I asked for and test it out within minutes of seeing David's suggestion. Some advantages claimed in the documentation that I haven't tested are: Correctly identifying left- and right-side pages if they are different; working inside floats; being able to change the top and bottom margins as well as left and right. – Michael Underwood Jul 30 '10 at 22:58
  • 2
    This is a very elegant solution. Works perfectly, even inside a float (which is where i needed it). – Trevor Oct 22 '12 at 22:17
  • The command dont works if you use it with a long text running across pages in a document definided with not equals inner and outer margins. – Raffaele Santoro Dec 28 '13 at 03:44
  • 1
    There is a small issue with the code. It adds additional margin on the top and bottom (prominently top). So if I use \begin{equation} \end{equation}, it adds even more space top and bottom. – Zero Nov 29 '16 at 17:26
  • This did not work for me. One of arguments #1 and #2 gets gobbled but the other lies freeform in the text. – Caleb Stanford Jun 05 '22 at 12:19
  • This is an elegant solution. As @RaffaeleSantoro points out it doesn't work with changing margins in a twoside layout. Is there a solution where for instance left and right margin adjustments switches between even/odd pages? Like the adjustwith*-command from the package changepage as mentioned in the respoonse above. – Rasmus Gross Søgaard Jun 29 '23 at 14:55
  • Vivi's solution works very well, as well as the one by David Z. However, none covers footnotes, which remain within the standard page pargin of the rest of the document. Anyone knows how to have footnotes to be included? – lomper Mar 07 '24 at 10:34
97

There are several packages available on CTAN to do this. changepage looks promising but you can find other alternatives by searching for "margins" or "changepage" on ctan search.

With the changepage package, you can use the adjustwidth environment as follows:

\begin{adjustwidth}{left amount}{right amount}
\lipsum[2]
\end{adjustwidth}

For example, to remove 100pt from the margin on both sides, you would use

\begin{adjustwidth}{100pt}{100pt}
inavda
  • 136
  • 1
  • 7
David Z
  • 12,084
  • 7
  • 48
  • 65
  • 9
    changepage seems to do just what I'm after, through the \begin{adjustwidth}{left change length}{right change length} environment. Thanks! – Michael Underwood Jul 29 '10 at 17:49
  • 2
    A little more specifically, \begin{adjustwidth}{50pt}{-200pt} XXX \end{adjustwidth} adds 50pt to the left margin and subtracts 200pt from the right margin. –  May 14 '18 at 05:20
  • 1
    Those who use the memoir class wiil find it already defines the adjustwidth environment, so no additional package is needed. – jcr Oct 18 '21 at 09:47
  • David Z's solution works very well, as well as the one by Vivi. However, none covers footnotes, which remain within the standard page pargin of the rest of the document. Anyone knows how to have footnotes to be included? – lomper Mar 07 '24 at 10:34
37

With either one of the KOMA-Script classes or the package scrextend (which is part of KOMA-Script), you can use the addmargin environment.

\documentclass{article}

\usepackage{scrextend}

\usepackage[english]{babel}
\usepackage{blindtext}

\begin{document}

\blindtext

% Syntax: \begin{addmargin}[<left indentation>]{<indentation>}
\begin{addmargin}[4em]{1em}
\blindtext
\end{addmargin}

\blindtext

\end{document}

enter image description here

lockstep
  • 250,273
  • 1
    thanks for that, that's exactly what i've been looking for for a while now. – David Wright Apr 21 '13 at 12:55
  • N.B. If used within an enumerated environment, this will remove the enumeration, i.e. you can't use it to adjust the margin of enumerated items. – Rax Adaam Apr 10 '18 at 15:47
13

Earlier versions of the geometry package did not allow to change the margins inside the document. The package gmeometric could help then.

Today geometry supports changing the margin inside the document by its commands \newgeometry{...} accepting the same key=value arguments and by \restoregeometry, see the manual of the current package version.

lockstep
  • 250,273
Stefan Kottwitz
  • 231,401
6

what about the \narrower (TeX?) command? Is it ok to use even though it does not offer a very precise control?

\documentclass[11pt]{book}
\usepackage[latin1]{inputenc}
\usepackage[a4paper,top=3.5cm,bottom=3cm,left=3.6cm,right=3.6cm]{geometry}
\usepackage{lipsum}
\begin{document}
\lipsum[4]
{\narrower\lipsum[4]
\par}
\lipsum[4]
\lipsum[4]
\lipsum[4]
\lipsum[4]
{\narrower\narrower\narrower \lipsum[4]
\par}
\lipsum[4]
\end{document}
lockstep
  • 250,273
pluton
  • 16,421
  • 2
    \narrower will indent the text by one \parindent. For more precise control one can also use \hskip 10pt etc. Of course is ok if you only want to indent once. \narrower\narrower will indent both left and right. – yannisl Sep 30 '10 at 01:47
4

It might not answer the question directly, but:

There is a letter class:

\documentclass{letter}

for writing letters.

And for verse there is a package called...wait for it...verse:

\usepackage{verse}

As I said, it doesn't answer the specific question, but it might solve the two applications you want the solution for.

Yossi Farjoun
  • 13,274
  • 10
  • 74
  • 96
0

Expanding on Vivi’s answer, it's possible to use the list environment and manually change all other list parameters to whatever values are in effect in the surrounding text:

\ExplSyntaxOn
\NewDocumentEnvironment{addmargin}{mm}{
    \list{}{
        \UseName{@beginparpenalty}=0
        \UseName{@itempenalty}=0
        \UseName{@endparpenalty}=0
        \setlength{\leftmargin}{#1} % Use `setlength' so calc will evaluate expressions
        \setlength{\rightmargin}{#2}
        \labelwidth=0pt
        \labelsep=0pt
        \itemindent=\parindent
        \listparindent=\parindent
        \parsep=\parskip
        \topsep=0pt
        \partopsep=0pt
        \itemsep=0pt
    }
    \item[]
}{
    \endlist
}
\ExplSyntaxOff
DGrady
  • 532