9

I want all math blocks \begin{math} in my document to be intended automatically, like it's the case with \begin{itemize}.

Can anyone please give me a hint on how to do this? Thanks :-)

  • 6
    \begin{math} is by definition in inline mode where an indentation makes no sense. – user2478 Mar 13 '13 at 16:02
  • \begin{equation*} ... \end{equation*} will display and center. Related: tex.stackexchange.com/questions/98397/enumerate-formulas/… . – Ethan Bolker Mar 13 '13 at 16:23
  • @EthanBolker As far as I know \begin{equation*} ... \end{equation*} indents the math, but still aligns it left by default. – Dave Mar 13 '13 at 16:27
  • 1
    @Dave the star form only differs in not providing an equation number. How the formula is displays depends on other settings and the default is centering, see my answer. – Frank Mittelbach Mar 16 '13 at 17:35
14

Left-aligned formulas

As mentioned in the comments \begin{math}is producing inline math, i.e., short bits and pieces within a paragraph, so indentation doesn't make sense here. So What you probably meant is that "display formulas", e.g., those produced with \[...\] or \begin{equation}..., etc. are left aligned (with indentation) rather than centered which is the default.

If this is the case then the simple answer to your question is to use the class option fleqn. The intention amount is defined by the variable \mathindent. This is implementated already by the standard classes, so

\documentclass[fleqn]{article}

works, but a different (and perhaps better) implementation is also provided by the amsmath package that is anyway preferable if the document contains any amount of serious math stuff.

Centered but also indented formulas

If your intention is to have centered formulas but with always a minimum indention from the left margin then the following definition of \indentdisplays should do the trick.

\documentclass[]{article}

\newcommand\sometext{Some text to get us a bit more than a line of material for testing. 
Some text to get us a bit more than a line of material for testing.}

\setlength\textwidth{7.6cm}

\newcommand\indentdisplays[1]{%
     \everydisplay{\setlength\displayindent{#1}%
     \addtolength\displaywidth{-\displayindent}}}

\begin{document}

\sometext
\begin{equation} a^2 + b^2 = c^2 \quad \textrm{a lot of math material here} \end{equation}

\indentdisplays{\parindent}  % <--- here we change for illustrations
\sometext
\begin{equation} a^2 + b^2 = c^2 \quad \textrm{a lot of math material here} \end{equation}

\end{document}

This gives

enter image description here

As you can see, the second formula is shifted to the right so that a minimum of \parindent on the left is free, but it is still centered in the remaining space. Normally you would, of course, use the command in the preamble so that it applies to all formulas in the document.

Update: Fixing the centered solution

There is one issue with the solution above: inside of lists the value of \displayindent is not zero but holds the same value as the current list indentation, so redefinining it to be a fixed value will shift the available space for the formula in the wrong direction, so instead of \setlength we have to add our value to \displayident and instead of substracting the \displayindent from the width of the display we have to substract the value by which the formula should be indented additionally. So the resulting code would look like this:

\documentclass[]{article}

\newcommand\sometext{Some text to get us a bit more than a line of material for testing. 
Some text to get us a bit more than a line of material for testing.}

\setlength\textwidth{7.9cm}

\newcommand\indentdisplays[1]{%
     \everydisplay{\addtolength\displayindent{#1}%
     \addtolength\displaywidth{-#1}}}

\begin{document}
\sometext
\begin{equation} a^2 + b^2 = c^2 \quad \textrm{a lot of math material here} \end{equation}

\indentdisplays{2\parindent}   % <--- a minimal indent of 2\parindent
\sometext
\begin{equation} a^2 + b^2 = c^2 \quad \textrm{a lot of math material here} \end{equation}

\begin{itemize}
\item \sometext                         % <-- inside itemize \parindent is zero
\begin{equation} a^2 + b^2 = c^2 \quad \textrm{a lot of math material here} \end{equation}
\indentdisplays{20pt}             % <--- using a fixed value works of course
\item \sometext
\begin{equation} a^2 + b^2 = c^2 \quad \textrm{a lot of math material here} \end{equation}\end{itemize}
\end{document}

And if we run this through LaTeX we will get:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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