Document ClassesMargin in ams math

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
wheely_chairs
Posts: 26
Joined: Mon Jun 16, 2008 1:22 pm

Margin in ams math

Post by wheely_chairs »

Hi everyone,

Is there any way to redefine the margin used by the ams math package (say, to add some indent but maintain the centering)? According to the documentation:
The left margin of math enviroments is controlled by \@mathmargin
However, my understanding is that it's not possible to redefine \@ macros outside of class and style files?

Thanks,

Chris

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Margin in ams math

Post by phi »

It is possible, but you have to use \makeatletter ... \makeatother:

Code: Select all

\makeatletter
\setlength\@mathmargin{24pt}
\makeatother
wheely_chairs
Posts: 26
Joined: Mon Jun 16, 2008 1:22 pm

Re: Margin in ams math

Post by wheely_chairs »

Thanks a lot for your reply Phi. However, unfortunately it hasn't worked :-( Perhaps I have the wrong length? I tried \addtolength (and in desperation other things like \renewcommand). Any ideas?
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Margin in ams math

Post by phi »

Please post a MWE that shows what doesn't work. I tested the following and could move the left margin:

Code: Select all

\documentclass[fleqn]{article}

\usepackage{amsmath}

\makeatletter
\setlength\@mathmargin{100pt}
\makeatother


\begin{document}

\begin{equation}
u
\end{equation}

\end{document}
wheely_chairs
Posts: 26
Joined: Mon Jun 16, 2008 1:22 pm

Re: Margin in ams math

Post by wheely_chairs »

Sorry, I should have made it clearer that I wanted to maintain equation centering (and hence wasn't using the fleqn option).

Thanks :-)
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Margin in ams math

Post by phi »

OK, then try it with a minipage:

Code: Select all

\hspace{5cm}
\begin{minipage}{5cm}
  \begin{equation}
    u
  \end{equation}
\end{minipage}
wheely_chairs
Posts: 26
Joined: Mon Jun 16, 2008 1:22 pm

Margin in ams math

Post by wheely_chairs »

For reference, I recently came up with a better solution by redefining the math environments:

Code: Select all

\usepackage{calc} % to make calculations with lengths
\newlength{\myMargin}
\setlength{\myMargin}{5em}

Code: Select all

% For align environments:
\let\oldalign\align
\let\endoldalign\endalign
\renewenvironment{align}{%
\oldalign\hspace{\myMargin}}{%
\endoldalign\ignorespacesafterend}

Code: Select all

% For multline environments:
\let\oldmultline\multline
\let\endoldmultline\endmultline
\renewenvironment{multline}{%
\oldmultline\hspace{\myMargin}}{%
\endoldmultline\ignorespacesafterend}

Code: Select all

% For normal equations they still have to go in
% minipages because alignment characters send the
% equation to the left otherwise - quite strange
\let\oldequation\equation
\let\endoldequation\endequation
\renewenvironment{\myMargin}%
{\par\begin{minipage}[b]{\linewidth-\myMargin}
\begin{oldequation}
}%
{
\end{oldequation}
\end{minipage}
\par
}
I may have missed some environments - these are the ones I use most frequently, but I'm sure the solution could be extended.
Post Reply