Document ClassesAlignment of separate characters

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
boneill3
Posts: 3
Joined: Wed Aug 06, 2008 3:53 am

Alignment of separate characters

Post by boneill3 »

Hello all,
I was wondering if someone could please help me to align the \equiv (equivalant sign) and the = signs in the following code


Code: Select all

\begin{align}

\Gamma(x) &\equiv \lim_{n \rightarrow \infty}\displaystyle\prod_{v=0}^{n - 1}\frac{n! n^{x-1}}{x = v} \\
&= \lim_{n \rightarrow \infty} \frac{n!n^{x-1}}{x(x + 1)...(x + n - 1)}\\
&= \int_{0}^{\infty}e^{-t}t^{x-1}dt\\

\end{align}  	

Is it possble to align multiple characters this way? or am I off track

regards
Brendan

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: Alignment of separate characters

Post by localghost »

I'm afraid I don't understand what you mean. The result of this code is a proper alignment of the equivalent sign and the equal signs. I guess you have to clarify what part of the result is insufficient for you.


Best regards and welcome to the board
Thorsten¹
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Alignment of separate characters

Post by Stefan Kottwitz »

Hi Brendan,

welcome to the board!
There are two small mistakes in the code. Remove the empty lines inside the align environment, they are equivalent to paragraph breaks and those are not allowed inside math environments. Furthermore don't use \\ at the end of the last line, else you will get an empty but numbered line additionally. Beside that the alignment should work, that's the code with the corrections mentioned above:

Code: Select all

\begin{align}
\Gamma(x) &\equiv \lim_{n \rightarrow \infty}\displaystyle\prod_{v=0}^{n - 1}\frac{n! n^{x-1}}{x = v} \\
&= \lim_{n \rightarrow \infty} \frac{n!n^{x-1}}{x(x + 1)...(x + n - 1)}\\
&= \int_{0}^{\infty}e^{-t}t^{x-1}dt
\end{align}
Stefan
LaTeX.org admin
boneill3
Posts: 3
Joined: Wed Aug 06, 2008 3:53 am

Re: Alignment of separate characters

Post by boneill3 »

Thanks Guy's I tried the code and works great!
I've just started this Topic and I didn't realise just how a extra line break etc. can cause so much grief.
once again thanks.
regards
Brendan
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Alignment of separate characters

Post by Juanjo »

From a mathematical viewpoint, I don't find convenient to number each term of a chain of relations, but the chain as a whole. So, in this case, I would suppress numbering, using align* instead of align, or I would assign a unique number, by means of equation and split:

Code: Select all

\begin{equation}
  \begin{split}
   \Gamma(x) &\equiv \lim_{n\to\infty}\prod_{v=0}^{n-1}\frac{n!\,n^{x-1}}{x+v} \\
   &=\lim_{n\to\infty} \frac{n!\,n^{x-1}}{x(x + 1)\cdots(x+n-1)} \\
   &=\int_{0}^{\infty} e^{-t}t^{x-1}\,dt
  \end{split}
\end{equation}
Let us also remark the following points:
  • In your code, there is a missprint in the denominator of the first fraction, which should be x+v instead of x=v.
  • Ellipsis in binary relations or operations (sum, product, < or >...) is represented by centered dots, obtained with \cdots. For example, write $a+\cdots+z$, but not $a+\ldots+z$ nor $a+...+z$.
  • You can use \to instead of \rightarrow, which requires fewer keystrokes.
  • The \displaystyle command in your code is superfluous.
  • It is convenient to add small spaces (for example, with \,) for fine tuning of some expressions.
  • Formulas should be punctuated as ordinary text. At the end, after dt, there should surely be a comma or a point, depending on the text which follows the math expression.
Perhaps you may like the := symbol instead of \equiv to denote definitions. If this were the case, you may get that symbol through the txfonts/pxfonts. Or simply through the following code:

Code: Select all

\newcommand{\coloneqq}{\mathrel{\mathop:}=}
\begin{equation}
  \begin{split}
   \Gamma(x) \coloneqq{}& \lim_{n\to\infty}\prod_{v=0}^{n-1}\frac{n!\,n^{x-1}}{x+v} \\
   ={}& \lim_{n\to\infty} \frac{n!\,n^{x-1}}{x(x + 1)\cdots(x + n - 1) }\\
   ={}&\int_{0}^{\infty} e^{-t}t^{x-1}\,dt
  \end{split}
\end{equation}
I've rewritten the formula to show that, if \coloneqq is used, I find better to align after the symbols (remark that \coloneqq and = have different lenghts). The pairs of braces are required (if they where absent, LaTeX would not interpret = and \coloneqq as binary relations, leading to improper spacing after those symbols.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
boneill3
Posts: 3
Joined: Wed Aug 06, 2008 3:53 am

Re: Alignment of separate characters

Post by boneill3 »

Thanks alot guys
I can see That I've got a lot of Learning to do.
Also I see with the use of \cdots that the code is alot more readable.
Thanks for the Tips
regards
Brendan
User avatar
T3.
Posts: 208
Joined: Fri Mar 14, 2008 12:58 pm

Alignment of separate characters

Post by T3. »

I have a another question about alignment, which is somewhat related to the original one, so I will ask it here.

Some time ago, I had a problem with an alignment of formula similar to this:

Code: Select all

\begin{align}
\eta &= \left(1 - \frac{\alpha}{n}\right)^n \\
     &\stackrel{n \to \infty}{=} \exp(-\alpha)
\end{align}\
I ended up kerning things manually but I wonder if anyone could think of some automated way to do it elegantly and without extensive TeX hacking. Consider this a challenge ;) .

Cheers,

Tomek
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Alignment of separate characters

Post by localghost »

You could do a (dirty?) trick by using a horizontal phantom.

Code: Select all

\begin{align}
  \eta &\stackrel{\hphantom{n\to\infty}}{=} \left(1-\frac{\alpha}{n}\right)^n \\
       &\stackrel{n\to\infty}{=} \exp(-\alpha)
\end{align}
This may be a suitable alignment for you. Perhaps you find more hints in "Math mode".


Best regards
Thorsten¹
User avatar
T3.
Posts: 208
Joined: Fri Mar 14, 2008 12:58 pm

Re: Alignment of separate characters

Post by T3. »

Thanks Thorsten. That's a nice solution. In my original equation it was visually more pleasing to just shift the second equation instead of increasing the space around equal sign in the first one, but I suppose your solution is more "proper".

Cheers,

Tomek
Post Reply