2

For some reason, some environments which are supposed to center mathematical equations aren't doing so, neither am I able to manually align them to the left or center them. I'm using mathtools and, whenever I write equations in an align or align* environment, they are automatically flushed to the right. I tried to use flalign instead (and many other formatting gimmicks) and it didn't solve the problem. What can I be doing wrong?

Edit:

\documentclass[hidelinks,article]{abntex2}
\usepackage[utf8]{inputenc}
\usepackage{titlesec}
\usepackage{mathtools}
\usepackage{amsfonts}
\begin{document}
\subsection{Algoritmo recursivo para o primeiro problema}
Como proposta de algoritmo recursivo \textbf{sem} recursão na cauda para a computação do MDC de dois números, foi elaborado o seguinte método: 
\begin{align}
{N \times N \implies N} \\
MDC(m,n)=1, se mindiv(m,n)=0 \\
\mathit{MDC(m,n)=mindiv(m,n)\times MDC  \left(\dfrac{m}{mindiv(m,n)},\dfrac{n}{mindiv(m,n)}\right), se        \hspace{2pt} mindiv\left(m,n\right)\in\mathbb{N}} \\
\mathit{mindiv(m,n): N \times N \implies N} \\
\mathit{mindiv(m,n)=min\left\{d\in\mathbb{N} \vert mod(m,d)=0 \wedge mod(n,d)=0 \wedge d\neq1  \right\}}
\end{align}
\end{document}

corresponding output

6
  • 1
    If you show use what your code looks like - something that replicates the problem, a minimal working example (MWE) - then we can probably tell you. Otherwise I'm pulling out my crystal ball...
    – Werner
    Apr 9, 2015 at 0:01
  • Ew, sorry, forgot to add preambule this time. Apr 9, 2015 at 0:12
  • 1
    align 'needs' & as alignment indicator, but I fear, the 3rd equation is too wide to provide some proper alignment with centering
    – user31729
    Apr 9, 2015 at 0:15
  • Actually, I wanted to align this block of equations to the left. From what I understood, that would be the purpose of using the flalign environment (which I tried using as well), for example, but even inside it the equations would appear aligned to the right. Apr 9, 2015 at 0:19
  • Your language is obviously Portuguese, consider \usepackage[portuguese]{babel} for example in your real document...
    – user31729
    Apr 9, 2015 at 0:34

2 Answers 2

3

I used the MWE by the OP and added align and flalign environments with 'correct' & settings. This improves the situation a little bit, but the middle equation is too wide, in my opinion.

The function names should be typeset with a \DeclareMathOperator command, not with \mathit, in my point of view, but ... you know ;-)

\documentclass[hidelinks,article]{abntex2}
\usepackage[utf8]{inputenc}
\usepackage{titlesec}
\usepackage{mathtools}
\usepackage{amsfonts}
\begin{document}
\subsection{Algoritmo recursivo para o primeiro problema}
Como proposta de algoritmo recursivo \textbf{sem} recursão na cauda para a computação do MDC de dois números, foi elaborado o seguinte método: 


Original version
\begin{align}
{N \times N \implies N} \\
MDC(m,n)=1, se mindiv(m,n)=0 \\
\mathit{MDC(m,n)=mindiv(m,n)\times MDC  \left(\dfrac{m}{mindiv(m,n)},\dfrac{n}{mindiv(m,n)}\right), se        \hspace{2pt} mindiv\left(m,n\right)\in\mathbb{N}} \\
\mathit{mindiv(m,n): N \times N \implies N} \\
\mathit{mindiv(m,n)=min\left\{d\in\mathbb{N} \vert mod(m,d)=0 \wedge mod(n,d)=0 \wedge d\neq1  \right\}}
\end{align}

Align
\begin{align}
N \times N &\implies N \\
\mathit{MDC(m,n)}&=1, \textit{se\;mindiv(m,n)}=0  \\
\mathit{MDC(m,n)}&=\mathit{mindiv(m,n)\times MDC  \left(\dfrac{m}{mindiv(m,n)},\dfrac{n}{mindiv(m,n)}\right)}, &\mathit{se\;mindiv}\left(m,n\right)\in\mathbb{N} \\
\mathit{mindiv(m,n)} &: N \times N \implies N \\
\mathit{mindiv(m,n)} &=\mathit{min\left\{d\in\mathbb{N} \vert mod(m,d)=0 \wedge mod(n,d)=0  \wedge d\neq1  \right\}}
\end{align}

flalign
\begin{flalign}
N \times N &\implies N \\
\mathit{MDC(m,n)}&=1, \textit{se\;mindiv(m,n)}=0  \\
\mathit{MDC(m,n)}&=\mathit{mindiv(m,n)\times MDC  \left(\dfrac{m}{mindiv(m,n)},\dfrac{n}{mindiv(m,n)}\right)}, &\mathit{se\;mindiv}\left(m,n\right)\in\mathbb{N} \\
\mathit{mindiv(m,n)} &: N \times N \implies N \\
\mathit{mindiv(m,n)} &=\mathit{min\left\{d\in\mathbb{N} \vert mod(m,d)=0 \wedge mod(n,d)=0  \wedge d\neq1  \right\}}
\end{flalign}

\end{document}

enter image description here

1
  • Of course, there might be more clever ways
    – user31729
    Apr 9, 2015 at 0:32
3

Since you're not using any alignment points (&), and given that the five equations don't seem to offer obvious places where alignment points should be inserted, you may be better off with a gather environment instead of an align environment.

Separately, I would take care to define terms such as mindiv as "math operators" and to typeset the string "MDC" using upright ("roman") letters. Consider using \mid instead of | to get typographically correct spacing around the vertical bar, and using \colon instead of :, again for spacing reasons.

enter image description here

\documentclass[hidelinks,article]{abntex2}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{amsmath,amsfonts}
\DeclareMathOperator{\mindiv}{mindiv}
\let\mod\relax  % redefine "\mod"
\DeclareMathOperator{\mod}{mod}
\newcommand{\MDC}{\mathrm{MDC}}

\begin{document}
\subsection{Algoritmo recursivo para o primeiro problema}

Como proposta de algoritmo recursivo \textbf{sem} recursão na cauda 
para a computação do MDC de dois números, foi elaborado o seguinte método: 
\begin{gather}
{N \times N \implies N} \\
\MDC(m,n)=1, \text{ se $\mindiv(m,n)=0$} \\
\MDC(m,n)=\mindiv(m,n)\times \MDC  
          \left(\dfrac{m}{\mindiv(m,n)},\dfrac{n}{\mindiv(m,n)}\right), 
          \text{ se  $\mindiv(m,n)\in\mathbb{N}$} \\
\mindiv(m,n)\colon N \times N \implies N \\
\mindiv(m,n)=\min \{\, d\in\mathbb{N} \mid 
             \mod(m,d)=0 \wedge 
             \mod(n,d)=0 \wedge d\neq1  \,\}
\end{gather}
\end{document}

You must log in to answer this question.

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