Generalaligning equations and spacing with inparaenum

LaTeX specific issues not fitting into one of the other forums of this category.
dmt
Posts: 82
Joined: Sat Mar 15, 2008 8:13 pm

aligning equations and spacing with inparaenum

Post by dmt »

I need some help with two questions:

1) aligning equations. I know the basic of the align and eqnarray environments, but I need to fine tune a bit.

2) spacing between inparaenum items

I am writing the solution set for some math problems, and each problem is numbered, and then has subsections with letters, so I am using nested enumerates. Like this:

8. (a) ....

Generally I have the solution start immediately after the letter. In some situations I have several lines of equations that i would like to align around the equal sign. I tried using both the align and eqnarray environments, but they both had the same problem ... they centered the equations on the page and skipped the first line.

I would like the first like to appear right after the letter:

8. (a) cos x = ....

and have the equations under it align with that equal sign (the first equation can be moved to the right a little if necessary for alignment purposes, but not centered).

How do I do this?

The second question is that when I have a bunch of short answers for a problem, I would like them to be listed in line instead vertically.

I found inparaenum that does this, but it puts too little space between the elements in the list. I had to add the space manually. Is there a way to set the default spacing used?

For example, by default I get something like this:

2. (a) cos 45 (b) sin 30 (c) tan 90

and I want something more like this:

2. (a) cos 45 (b) sin 30 (c) tan 90

Thanks for any help I can get.

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

aligning equations and spacing with inparaenum

Post by Stefan Kottwitz »

Hi dmt!

My idea concerning your equation alignment is: use the fleqn-Option of amsmath for left alignment and change some predefined lengths to get the result. Define your own align-environment:

Code: Select all

\usepackage[fleqn]{amsmath}
\newenvironment{myalign}{%
    \setlength{\mathindent}{0pt}%
    \setlength{\abovedisplayskip}{-\baselineskip}%
    \setlength{\abovedisplayshortskip}{\abovedisplayskip}%
    \align
  }%
  {\endalign}
...
\begin{enumerate}
  \item \begin{myalign}
       ... \end{myalign}
...
Stefan
dmt
Posts: 82
Joined: Sat Mar 15, 2008 8:13 pm

Re: aligning equations and spacing with inparaenum

Post by dmt »

Wow, thanks, that worked really well. Just one more question about that part ... how do I get rid of the equation numbers with my own environment (equivalent to using \being{align*} instead of \begin{align}) ?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

aligning equations and spacing with inparaenum

Post by Stefan Kottwitz »

Hi dmt,

here is the modification for a starred myalign-environment:

Code: Select all

\makeatletter
\newenvironment{myalign*}{%
    \setlength{\mathindent}{0pt}%
    \setlength{\abovedisplayskip}{-\baselineskip}%
    \setlength{\abovedisplayshortskip}{\abovedisplayskip}%
    \start@align\@ne\st@rredtrue\m@ne
  }%
  {\endalign}
\makeatother
Stefan
dmt
Posts: 82
Joined: Sat Mar 15, 2008 8:13 pm

Re: aligning equations and spacing with inparaenum

Post by dmt »

Once again exactly what I needed. Thanks!

Now if only someone had an equally good solution to the inparaenum problem ...
balf
Posts: 158
Joined: Sat Jan 12, 2008 1:11 am

Re: aligning equations and spacing with inparaenum

Post by balf »

You should try the shortlst package: il has shortitemize, shortenumerate, runitemize and runenumerate environments, the spacing is better, and you can control it through a \runitemsep length. That's what I use (with somehacks) for my lists of answers to exercises.

B.A.
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

aligning equations and spacing with inparaenum

Post by Juanjo »

Let's see another approach for both problems, exemplified in the following code:

Code: Select all

\documentclass{article}

\usepackage{amsmath}
\usepackage{paralist}

\newenvironment{myinparaenum}%
   {\begin{inparaenum}[\hspace{2em}(a)]\hspace{-2em}\ignorespaces}%
   {\end{inparaenum}}

\begin{document}

\begin{enumerate}
\item $\begin{aligned}[t]
          a&=b+c+d+e+f+g+h+i \\
           &=j+k+l+m+n+p \\
           &=q+r+s+t
       \end{aligned}$
 \item \begin{inparaenum}[(a)]
           \item $\sin \pi/4$ \item $\cos  \pi/7$ \item $\tan 3\pi/5$
       \end{inparaenum}
 \item \begin{myinparaenum}
              \item $\sin \pi/4$ \item $\cos  \pi/7$ \item $\tan 3\pi/5$
       \end{myinparaenum}
\end{enumerate}

\end{document}
Concerning alignment, in addition to align, alignat and gather environments (and their starred forms), the amsmath package provides the aligned, alignedat and gathered environments, which provides almost the same functionality and have quite similar syntax. The latter environments can be used everywhere in math mode and they have an optional argument for alignment with the surrounding material.

Concerning the space between in a inparaenum environment, it can be increased with \hspace, considering that space as part of the item label. See the above definition of myinparaenum. You can replace both instances of 2em by a length suiting your needs.
dmt
Posts: 82
Joined: Sat Mar 15, 2008 8:13 pm

Re: aligning equations and spacing with inparaenum

Post by dmt »

Thanks folks. I'll check out these new ideas.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Re: aligning equations and spacing with inparaenum

Post by Stefan Kottwitz »

Hi Juanjo,

this is really an elegant approach!
I like amsmath for its flexible environments, so why not take some more time to choose the environment more carefully to meet the requirements, next time for me... instead of beginning to program a workaround. :D

Stefan
dmt
Posts: 82
Joined: Sat Mar 15, 2008 8:13 pm

Re: aligning equations and spacing with inparaenum

Post by dmt »

I was unable to install shortlst for some reason. I followed the directions in the pdf and put the .sty file in the misc directory, but latex is complaining that it can't find it. Anyone had this problem?

By the way, the {aligned}[t] environment was great. Thanks.
Post Reply