2

I set the margins of the document but if I write a too long equation only using $$...$$, align*, or equation* and then aligned environments centers the equation, but from the left margin.

So the question is, How to center an equation considering only the width of the document, and not the margins?

Here is my MWE:

\documentclass{article}
\usepackage{amsmath}
\usepackage{vmargin}

\setpapersize{A4}
\setmargins{2.2cm}
{0.5cm}
{16.5cm}
{23.42cm}               
{30pt}
{1cm}
{0pt}
{2cm}   

\begin{document}

% With $$...$$ there is less spacing. I definitely do not want to use this option.
$$
a_n=\sqrt[n]{n}=1+h\Rightarrow n={(1+h)}^n\underbrace{=}_{\substack{\text{Por binomio de Newton}\\\text{(Ver \textbf{OBSERVACI\'ON})}}}1+nh+\dfrac{n(n-1)}{2!}h^2+\cdots +h^n\underbrace{\geq}_{\substack{\text{Como todos los sumandos son}\\\text{positivos, se puede acotar}\\\text{inferiormente con uno solo}\\\text{de ellos}}} \dfrac{n(n-1)}{2!}h^2.
$$

% With equation* and aligned environments space properly, but center from the left margin.
\begin{equation*}
    \begin{aligned}
        a_n=\sqrt[n]{n}=1+h\Rightarrow n={(1+h)}^n\underbrace{=}_{\substack{\text{Por binomio de Newton}\\\text{(Ver \textbf{OBSERVACI\'ON})}}}1+nh+\dfrac{n(n-1)}{2!}h^2+\cdots +h^n\underbrace{\geq}_{\substack{\text{Como todos los sumandos son}\\\text{positivos, se puede acotar}\\\text{inferiormente con uno solo}\\\text{de ellos}}} \dfrac{n(n-1)}{2!}h^2.
    \end{aligned}
\end{equation*}

% With align* environment it is the same as with equation* and aligned environments.
\begin{align*}
    a_n=\sqrt[n]{n}=1+h\Rightarrow n={(1+h)}^n\underbrace{=}_{\substack{\text{Por binomio de Newton}\\\text{(Ver \textbf{OBSERVACI\'ON})}}}1+nh+\dfrac{n(n-1)}{2!}h^2+\cdots +h^n\underbrace{\geq}_{\substack{\text{Como todos los sumandos son}\\\text{positivos, se puede acotar}\\\text{inferiormente con uno solo}\\\text{de ellos}}} \dfrac{n(n-1)}{2!}h^2.
\end{align*}

\end{document}

And the result is:

Different ways of writing an equation, but none works.

Thanks!

manooooh
  • 3,203
  • 2
  • 21
  • 46
  • Your equation is longer than the available length (paper width minus the left and right margins), so it starts right after the left margin and occupies whatever is needed from the right margin. Do you want to center it however, occupying parts of the margin, or do you want to manually adjust your equation so it is small enough and can be centered in the space between the margins? – Karlo Jan 17 '18 at 17:40
  • 1
    not relevant to the question, but the baselines of the text in the \substacks aren't at all even. if you add a \strut in each line, these will even out and look better. – barbara beeton Jan 17 '18 at 17:51
  • 1
    @Karlo The first one. Regardless of the values of the margins I want to center this type of long equations (and why not any other). It makes me nervous to see that the equations are centered respecting the margin haha. – manooooh Jan 17 '18 at 18:12
  • @barbarabeeton Can you give me an example please? I do not understand :(. – manooooh Jan 17 '18 at 18:15
  • 1
    \substack{\text{Como todos los sumandos son\strut}\\\text{positivos, se puede acotar\strut}\\\text{inferiormente con uno solo\strut}\\\text{de ellos\strut}} -- this is most obvious in the second line of your examples. – barbara beeton Jan 17 '18 at 19:46
  • @barbarabeeton Thanks! I will try to implement it. – manooooh Jan 17 '18 at 19:57

3 Answers3

5

This doesn't directly address the margins issue, but to make the equation short enough to fit within your margins, you might consider using \mathclap from the mathtools package (which should be used instead of, not in addition to amsmath).

Note also that you should use \[..\] instead of $$..$$. Explanation here.

enter image description here

\documentclass{article}
\usepackage{mathtools}
\usepackage{vmargin}

\setpapersize{A4}
\setmargins{2.2cm}
{0.5cm}
{16.5cm}
{23.42cm}               
{30pt}
{1cm}
{0pt}
{2cm}   

\begin{document}

\[
a_n=\sqrt[n]{n}=1+h\Rightarrow n={(1+h)}^n\underbrace{=}_%
    {\mathclap{\substack{\text{Por binomio de Newton}\\\text{(Ver \textbf{OBSERVACI\'ON})}}}}%
    1+nh+\dfrac{n(n-1)}{2!}h^2+\cdots +h^n\underbrace{\geq}_%
    {\mathclap{\substack{\text{Como todos los sumandos son}\\\text{positivos, se puede acotar}\\\text{inferiormente con uno solo}\\\text{de ellos}}}}%
    \dfrac{n(n-1)}{2!}h^2.
\]

\end{document}
Sandy G
  • 42,558
  • Thanks! Although it is not the answer I expected, I solve it in part :) (and from now on I will use the \[...\]. Since I speak Spanish and I often use the $ symbol I am more used to seeing it haha. But page 6, section 1.6 of the link that you attach to your link says specifically "Separating maths formulae from continuous text using $$...$$. Please do not do this!" Thanks for the warning! – manooooh Jan 17 '18 at 18:16
2

Setting text or equations in the margins is usually not the solution. Here I present a different way to display your argument.

Some important details: avoid vmargin, which is incompatible with several other packages, notably TikZ. The same settings can be more clearly obtained with geometry. The showframe option is just for drawing lines that illustrate the page setup. Remove it for the final version.

\documentclass{article}
\usepackage{amsmath}
\usepackage[
  showframe,
  a4paper,
  includehead,
  left=2.2cm,
  top=0.5cm,
  textwidth=16.5cm,
  textheight=23.42cm,
  heightrounded,
  headheight=30pt,
  headsep=1cm,
  footskip=2cm,
]{geometry}

\newcommand{\eqdesc}[1]{%
  \text{\footnotesize\begin{tabular}{@{}l@{}}#1\end{tabular}}%
}

\begin{document}

\begin{align*}
a_n=\sqrt[n]{n}=1+h
\implies
n &= (1+h)^n \\
  &= 1+nh+\frac{n(n-1)}{2!}h^2+\dots+h^n
&& \eqdesc{Por binomio de Newton\\(Ver \textbf{OBSERVACI\'ON})} \\
  &\geq \frac{n(n-1)}{2!}h^2.
&& \eqdesc{Como todos los sumandos son\\positivos, se puede acotar\\
           inferiormente con uno solo\\de ellos}
\end{align*}

\end{document}

enter image description here

egreg
  • 1,121,712
2

It's not very tidy, and it's not automatic, but you could use "\hspace*" to force equations left. If there are multiple wide equations, all wide equations need this treatment. Experiment with the values till it looks OK.

\documentclass{article}
\usepackage{amsmath}
\usepackage{vmargin}

\setpapersize{A4}
\setmargins{2.2cm}
{0.5cm}
{16.5cm}
{23.42cm}               
{30pt}
{1cm}
{0pt}
{2cm}   

\begin{document}

% With $$...$$ there is less spacing. I definitely do not want to use this option.
$$
\hspace*{-8mm}
a_n=\sqrt[n]{n}=1+h\Rightarrow n={(1+h)}^n\underbrace{=}_{\substack{\text{Por binomio de Newton}\\\text{(Ver \textbf{OBSERVACI\'ON})}}}1+nh+\dfrac{n(n-1)}{2!}h^2+\cdots +h^n\underbrace{\geq}_{\substack{\text{Como todos los sumandos son}\\\text{positivos, se puede acotar}\\\text{inferiormente con uno solo}\\\text{de ellos}}} \dfrac{n(n-1)}{2!}h^2.
$$

% With equation* and aligned environments space properly, but center from the left margin.
\begin{equation*}
    \hspace*{-11mm}
    \begin{aligned}
        a_n=\sqrt[n]{n}=1+h\Rightarrow n={(1+h)}^n\underbrace{=}_{\substack{\text{Por binomio de Newton}\\\text{(Ver \textbf{OBSERVACI\'ON})}}}1+nh+\dfrac{n(n-1)}{2!}h^2+\cdots +h^n\underbrace{\geq}_{\substack{\text{Como todos los sumandos son}\\\text{positivos, se puede acotar}\\\text{inferiormente con uno solo}\\\text{de ellos}}} \dfrac{n(n-1)}{2!}h^2.
    \end{aligned}
\end{equation*}

% With align* environment it is the same as with equation* and aligned environments.
\begin{align*}
    \hspace*{-11mm}
    a_n=\sqrt[n]{n}=1+h\Rightarrow n={(1+h)}^n\underbrace{=}_{\substack{\text{Por binomio de Newton}\\\text{(Ver \textbf{OBSERVACI\'ON})}}}1+nh+\dfrac{n(n-1)}{2!}h^2+\cdots +h^n\underbrace{\geq}_{\substack{\text{Como todos los sumandos son}\\\text{positivos, se puede acotar}\\\text{inferiormente con uno solo}\\\text{de ellos}}} \dfrac{n(n-1)}{2!}h^2.
\end{align*}

\end{document}
cwhctza
  • 78
  • 6