Text FormattingTrying to use "align" environment

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
itsmereally
Posts: 32
Joined: Sun Jul 25, 2010 11:15 pm

Trying to use "align" environment

Post by itsmereally »

Hello

I'm new to using LaTeX, and I'm having alot of trouble with things. At the moment, I'm trying to get the "align" environment to work.

If I copy & paste something from the "Not So Short Guide to LaTeX", it works, but if I then substitute my own text, it doesn't work. I get a message saying "! Missing } inserted" in the Console Output.

This is what I'm trying to align:

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
2.50 KiloWatts & = 2.50$kW$ \\
& = 2.50x10$^{3}W$
\end{align}
\end{document}
I hope this is okay. I don't understand what those minimal things are. Sorry.

I'd appreciate any help with this. I've spent over 2 hours trying various things now.
Last edited by itsmereally on Tue Jul 27, 2010 5:22 pm, edited 1 time in total.

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

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Trying to use "align" environment

Post by Stefan Kottwitz »

Hi,

the example is good. It's small, kind of complete and it shows the error.
$...$ is used for math inside normal text. Don't use it in align or equation environments. This works:

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
2.50 \text{ KiloWatts} & = 2.50 \text{ kW} \\
  &= 2.50\times10^3 \text{ W}
\end{align}
\end{document}
Stefan
LaTeX.org admin
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Trying to use "align" environment

Post by localghost »

For physical units I suggest to use the siunitx package. It typesets values and their units with appropriate space in between and works in math and text mode equally.


Best regards and welcome to the board
Thorsten
itsmereally
Posts: 32
Joined: Sun Jul 25, 2010 11:15 pm

Trying to use "align" environment

Post by itsmereally »

Thanks for the replies. :)

I managed to get that example working, however it isn't "exactly" what I needed. I'm now trying to get the aligned text on the left side of the page, and I'm trying to remove the numbers that appear on each aligned line.

I've been experimenting with \begin{equation*}, but the document won't compile, and \begin{flushleft} doesn't make any difference.

Any ideas?

There is also something else I'd like to ask about regarding the align environment.

I'm trying to align two lines of text, one starting with a bulletpoint and the other in-line with the first letter of the first line.

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
\textbullet \hspace{0.1cm} & Force is measured in newtons (\text{ N}), or \text{ kgms^{-2}} \\
& \text{ kgms^{-2}} is Mass (\text{ kg}) \times Acceleration (\text{ ms^{-2}})
\end{align}
\end{document}
I'm trying to line up the "F" of the first sentence with the "k" of the second.

I get a similar message in the Console Output as before: "! Missing $ inserted"

Thanks again.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Trying to use "align" environment

Post by Stefan Kottwitz »

Hi,
itsmereally wrote:I managed to get that example working, however it isn't "exactly" what I needed. I'm now trying to get the aligned text on the left side of the page, and I'm trying to remove the numbers that appear on each aligned line.
since there's so much text I recommend to use a tabular environment instead of a math environment like align.
itsmereally wrote: There is also something else I'd like to ask about regarding the align environment.
I'm trying to align two lines of text, one starting with a bulletpoint and the other in-line with the first letter of the first line.
You could use the itemize environment:

Code: Select all

\documentclass{article}
\begin{document}
\begin{itemize}
\item Force is measured in newtons (N), or kgms${}^{-2}$ \\
 kgms${}^{-2}$ is Mass (kg) $\times$ Acceleration (ms${}^{-2}$)
\end{itemize}
\end{document}
Stefan
LaTeX.org admin
itsmereally
Posts: 32
Joined: Sun Jul 25, 2010 11:15 pm

Trying to use "align" environment

Post by itsmereally »

Well, I've tried what you suggested, and unfortunately my document isn't looking anything like what I need. I'm having alot of trouble with conflicts, and I'm getting alot of error messages.

I can get your itemize example to work, but I'd like to have the units all in the same style, by putting them between $s. If I try to do that, the file stops compiling part way through. I'll give the siunitsx package a go once I've dealt with this alignment issue.

The align environment puts the text in the centre of the page, but I need all of the bulletpoints in-line down the left side of the page. I still haven't worked out how to remove the numbering either. The itemize and tabular environments put the text closer to the left of the page, but not as far as bulletpoints that aren't in any environment.

Code: Select all

\documentclass{article}
\begin{document}
\textbullet \hspace{0.1cm} There are \textbf{Base Physical Quantities} (Mass, Length etc)
\begin{itemize}
\item Force is measured in newtons (N), or kgms${}^{-2}$ \\
kgms${}^{-2}$ is Mass (kg) $\times$ Acceleration (ms${}^{-2}$)
\end{itemize}
\end{document}
This example is confusing me quite a bit. Inserted into a new document, the bulletpoint and the itemized environment are in-line. Inserted part way through my document (excluding the document parts), the bulletpoint is to the left of the page and the bulletpoint from the itemized environment is below and about an inch to the right.

Is there any way to use a horizontal space \hspace{} at the beginning of a line, before any text? Maybe that could sort things out for me, even though it will probably take more time.

The only other things I can think of are putting everything (non-titles) in the itemize environment, or not using bulletpoints, which is something I'd prefer not to do.

So confused. :oops:
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Trying to use "align" environment

Post by Stefan Kottwitz »

itsmereally wrote:I still haven't worked out how to remove the numbering either.
align* and other starred evironments aren't numbered.

So, if you insist on align, an example using the fleqn option:

Code: Select all

\documentclass[fleqn]{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
\bullet\quad& \text{Force is measured in newtons (N), or kgms}{}^{-2} \\
  & \text{kgms}^{-2} \text{ is Mass (kg) }\times
    \text{ Acceleration (ms}^{-2}\text{)}
\end{align*}
\end{document}
Alternatively:

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{flalign*}
\bullet\quad& \text{Force is measured in newtons (N), or kgms}{}^{-2} &\\
  & \text{kgms}^{-2} \text{ is Mass (kg) }\times
    \text{ Acceleration (ms}^{-2}\text{)} &
\end{flalign*}
\end{document}
Stefan
LaTeX.org admin
itsmereally
Posts: 32
Joined: Sun Jul 25, 2010 11:15 pm

Trying to use "align" environment

Post by itsmereally »

Code: Select all

\begin{flalign*}
\bullet\quad& \text{Force is measured in newtons (N), or kgms}{}^{-2} &\\
  & \text{kgms}^{-2} \text{ is Mass (kg) }\times
    \text{ Acceleration (ms}^{-2}\text{)} &
\end{flalign*}
That is exactly what I wanted, and it looks great. Thank you so much.

I was wondering if I could ask you about what you've done there.

1). I noticed that the \quad command changes the space between the bulletpoint and the start of the text. Are there any other commands that could go there to increase/decrease the space?

2). Does the align command put anything between the beginning and end in a math environment? I'm guessing that's why you've put the \text commands in there, so anything not within the \text command is read as math.

3). What do the "{}" do? I noticed you've used them before superscripts, but if I remove them I don't see any difference.

Again, thank you very much for your help. I genuinely appreciate it. I'd have been completely lost without this. :)
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Trying to use "align" environment

Post by Stefan Kottwitz »

itsmereally wrote:1). I noticed that the \quad command changes the space between the bulletpoint and the start of the text. Are there any other commands that could go there to increase/decrease the space?
You already used \hspace, it can be used with any lenght. There are some fixed-length commands, like \quad, \qquad, \, for \thinspace, \: for \medspace, \; for \thickspace, \! for negative thin space, further \negmedspace and \negthickspace ... some use these shortcuts \, and \! for instance or \quad, \qquad as shortcut, but everything could be done with \hspace as well.
Further there are of course vertical commands like \vspace, \bigskip and more.
itsmereally wrote:2). Does the align command put anything between the beginning and end in a math environment? I'm guessing that's why you've put the \text commands in there, so anything not within the \text command is read as math.
All inside the align environment is considered as math. \text has been used to temporarily switch back to text mode.
itsmereally wrote:3). What do the "{}" do? I noticed you've used them before superscripts, but if I remove them I don't see any difference.
{...} means grouping. Simply said, everything that's grouped by braces would be dealt by LaTeX like a single item. So X^22 could mean X squared and multiplied with 2, but X^{22} would mean X to the power of 22. { marks a start, } marks the end, also with arguments to commands. Further they limit the effect of commands or declarations inside.

Stefan
LaTeX.org admin
itsmereally
Posts: 32
Joined: Sun Jul 25, 2010 11:15 pm

Trying to use "align" environment

Post by itsmereally »

Thanks for all the info. I'm getting there, slowly.
Stefan_K wrote: {...} means grouping. Simply said, everything that's grouped by braces would be dealt by LaTeX like a single item. So X^22 could mean X squared and multiplied with 2, but X^{22} would mean X to the power of 22. { marks a start, } marks the end, also with arguments to commands. Further they limit the effect of commands or declarations inside.

Stefan
Sorry. I didn't make myself clear on that.

Code: Select all

kgms}{}^{-2}
Here, there is {} with nothing in it. It was that what I was asking about. :)
Post Reply