tags:

views:

940

answers:

6

I'm a mechanical engineer who's been doing her calculation reports in Word. However, ever since I knocked down my bedroom wall with my head banging on it from Word constantly driving me crazy, I've been looking at latex, and liking it. It is relatively user friendly and not too hard to get accustomed to.

However, I have a problem with it. Just to mention, distribution is miktex 2.7 on winxp, if that matters.

I'm trying to write my formulas in a way:

text text text text text text text text text text text text  
text text text text text text text text text text text text
a = b + c = 12m    measure of length of great importance  
   b = 6m          a measure of length  
   b1 = 28m        new text
   c1 + d = a + b  new text
   c = 8m          another measure of length  
                   and it is in meters

What would be the correct way to nicely justify these in this manner ? Is it possible at all ? I have a many of these (2 cm book thickness).

I'm a newbie concerning tex, so maybe this sounds trivial to you. But to me, after googling, it is still a problem. Please help. Save a wall.

EDIT by me: Just thought I'd explain a little better (although you guys already covered almost all the posibilities). I'm trying to left align b and c (the rest of the formula will vary, so it doesn't matter) and the text which explain the formulas, also left align.

+5  A: 

Yes, justification is a common case, and supported well in LaTeX. You want to use an align environment (\begin{align} ... \end{align}). Within that, each line of LaTeX (separated with \) will correspond to one formula, and you can choose which character you would like to have aligned on each line by placing an ampersand (&). In your example:

\begin{align}
a = b + c &= 12m\\
b &= 6m\\
c &= 8m\\
\end{align}

Should do something like what you're after (depending on how you want to justify the first line). This will number each equation for reference in the text; if this is not required or desired, use an align* environment instead. Adding a star after the environment name is a common idiom in LaTeX which means "don't number these," and can be used for sections and so forth as well.

EDIT: Here's another interpretation of the justification I think you want:

text text text text text text text text text text text text  
text text text text text text text text text text text text
\begin{align*}
a = &b + c = 12m &\text{measure of length of great importance}\\  
&b = 6m &\text{a measure of length}\\
&c = 8m &\text{another measure of length}\\ 
& &\text{and it is in meters}
\end{align*}

Note:

  • You can place multiple ampersands per line to specify multiple alignment points, but all lines must have the same number of alignment points.
  • align is a math environment.
  • \text{...} lets you put normal text in a math environment. There are many other commands to format text within a math environment.
Matt J
if you use array instead of align, you can do \begin{array}{rcll} which gives you 4 columns instead of 3 (With the first 3 showing up the same as align).
sharth
A: 

I won't attempt to address your question directly since it seems to have been addressed above. I will however suggest that you try LyX to ease yourself into the TeX world. It presents a graphical interface with immediate preview that may be more intuitive given your background using word and so on. It's built upon a LaTeX base, so you're using LaTeX commands where applicable, but it's still (in my opinion), a much easier introduction to TeX.

LyX

Kaushik
Thanks Kaushik, it looks nice, I'll try it. I started with LEd, since it had a preview inside so I can see directly what I've done.
+1  A: 

You may be the first person I've ever heard describe LaTeX as "user-friendly" ;-)

Anyway, it's not entirely clear whether you're trying to align specific parts of equations or just center them. There are different equation environments for different kinds of alignment, for instance the gather environment which centers each equation on its own line.

Side note: I'd recommend looking at the Not So Short Introduction to LaTeX2e, which is how I started learning LaTeX, and the User's Guide to the amsmath Package, which describes the different kinds of alignment available.

David Zaslavsky
On the whole, I find that LaTeX is pretty user-friendly. It's not necessarily beginner-friendly, though.
Vatine
A: 

I would recommend abstracting away from align and using this:

\begin{tabular}{rcll}
$a$ & $=$ & $12m$ & measure of length of great importance \\
$b$ & $=$ & $6m$  & a measure of length \\
\end{tabular}
sharth
is there a way to number each line as an equation? this approach has some benefits, particularly if you want to auto-justify fields, but it may be a dealbreaker if you want things to be numbered for reference in the text in the standard way.
Matt J
That's a terrible idea, sorry. The spacing will be completely wrong and, as Matt mentions, you'll have to write more code to do equation numbering.
Will Robertson
@Will - I use this a lot. Why do you think it is bad practice ? Could you explain ?
ldigas
The spacing around the equals sign will be terribly wrong; the markup is more complex than it needs to be; impossible to add equation numbers. Other solutions given on this page are much better. At the very least see @dmckee's answer above.
Will Robertson
I agree with about all the criticism, except that I think my solution is the only one that gets you lined up = signs and 4 areas to work with.There's probably a math mode equivalent of this though (which allows arbitrary number of columns)
sharth
A: 
Will Robertson
+1  A: 

You could use the standard eqnarray environment, or look at the more powerful tools available in the amsmath package.


If using eqnarray, you would put at least on positions anchor between the work and the text like this

\begin{eqnarray}
a = b + c = 12m  & & \mbox{measure of length of great importance}\\
   b = 6m        & & \mbox{a measure of length}\nonumber\\
...
\end{eqnarray}

lines are numbered by default, but \nonumber will suppress that. To prevent any line numbers use eqnarray* instead.


If you insist, you could use tables as well, but I don't recommend it. If you do, keep the whole formula in a single cell like:

\begin{tabular}{cl}
    $a = b + c = 12m$  & \mbox{measure of length of great importance}\\
    $b = 6m$           & \mbox{a measure of length}\\
 ...
\end{tabular}

this makes numbering hard.

dmckee
Shouldn't use eqnarray :) http://www.tug.org/pracjourn/2006-4/madsen
Will Robertson
@Will: Thanks. I hadn't seen that before, though I have been bitten by some of the described hazards.
dmckee