10

I'd like to typeset math in table layout, which is stretched to page width e.g.:

\begin{flalign*}
   a)\, \lim_{n\to\infty} \frac{1000n}{n^2+1} &&
   b)\, \lim_{n\to\infty} \left( \sqrt{n+1}-\sqrt{n}\right) &&
   c)\, \lim_{n\to\infty} \frac{\sqrt[3]{n}\sin n!}{n+1}&&\\
   d)\, \lim_{n\to\infty} \frac{(-2)^n+ 3^n}{(-2)^{n+1}+3^{n+1}}&&
\end{flalign*}

This produces output where each column is aligned to right, I'd prefer left align:

enter image description here

Moreover some padding between lines would be nice.

I've tried using an array environment:

\[
  \begin{array}{p{0.33\textwidth}p{0.33\textwidth}p{0.33\textwidth}}
   a)\, \displaystyle\lim_{n\to\infty} \frac{1000n}{n^2+1} &
   b)\, \displaystyle\lim_{n\to\infty} \left(\sqrt{n+1} - \sqrt{n}\right)&
   c)\, \displaystyle\lim_{n\to\infty} \frac{\sqrt[3]{n}\sin n!}{n+1}\\
   d)\, \displaystyle\lim_{n\to\infty} \frac{(-2)^n+ 3^n}{(-2)^{n+1}+3^{n+1}} 
 \end{array}
\]

enter image description here

It seem to solve the problem with align, but math commands inside array produces too many errors and space between rows is even smaller.

Any idea how to solve this?

3 Answers 3

12

You could use the normal align* environment, combined with the spreadlines environment from the mathtools package. The parameter for spreadlines (here 20pt) sets the linespacing for align and gather environments within it. Should you want this change to be global, you could instead add \setlength{\jot}{20pt} to your preamble.

\documentclass[12pt]{article}
\usepackage{mathtools}
\begin{document}
\begin{spreadlines}{20pt}
\begin{align*}
   &a)\, \lim_{n\to\infty} \frac{1000n}{n^2+1} &
   &b)\, \lim_{n\to\infty} \left( \sqrt{n+1}-\sqrt{n}\right) &
   &c)\, \lim_{n\to\infty} \frac{\sqrt[3]{n}\sin n!}{n+1}\\
   &d)\, \lim_{n\to\infty} \frac{(-2)^n+ 3^n}{(-2)^{n+1}+3^{n+1}}
\end{align*}
\end{spreadlines}
\end{document}

enter image description here

1
  • 1
    I see, I was using those ampersands incorrectly. Thanks, that's nice and simple.
    – Tombart
    Oct 30, 2011 at 11:02
4
\documentclass[a4paper]{article}
\usepackage{tabularx,array}
\newcolumntype{Y}{>{$\displaystyle\exer}X<{$}}
\newenvironment{exercises}[2][1.5]
  {\par\flushleft\setcounter{exercise}{0}
   \renewcommand{\arraystretch}{#1}\tabularx\linewidth{@{}#2@{}}}
  {\endtabularx\endflushleft}
\newcounter{exercise}
\renewcommand{\theexercise}{\alph{exercise}}
\newcommand{\exer}{\stepcounter{exercise}\makebox[1.2em][r]{\theexercise)\ }}

\begin{document}
\begin{exercises}[2.5]{YYY}
\lim_{n\to\infty} \frac{1000n}{n^2+1} &
\lim_{n\to\infty} \left(\sqrt{n+1} - \sqrt{n}\right)&
\lim_{n\to\infty} \frac{\sqrt[3]{n}\sin n!}{n+1}\\
\lim_{n\to\infty} \frac{(-2)^n+ 3^n}{(-2)^{n+1}+3^{n+1}}
\end{exercises}
\end{document}

You see that you only need to specify how many columns you need and, possibly, the amount of interline stretching. The numbering is automatic.

Alternative definition

Here the intercolumn space is stretched, rather than the column width

\newcolumntype{Y}{>{$\displaystyle\exer}l<{$}}
\newenvironment{exercises}[2][1.5]
  {\par\flushleft\setcounter{exercise}{0}
   \renewcommand{\arraystretch}{#1}
   \begin{tabular*}\linewidth{@{\extracolsep{\fill}}#2@{}}}
  {\end{tabular*}\endflushleft}
\newcounter{exercise}
\renewcommand{\theexercise}{\alph{exercise}}
\newcommand{\exer}{\stepcounter{exercise}\makebox[1.2em][r]{\theexercise)\ }}
2
  • Nice solution as well. For displaying it on full \textwidth I would need to pass some extra argument to tabularx?
    – Tombart
    Oct 30, 2011 at 11:13
  • It is on full line width; using \linewidth instead of \textwidth in the definition ensures that the environment will respect the line width also in list environments. You have three equal width columns. I'll add a different solution that gives "flush right" third column.
    – egreg
    Oct 30, 2011 at 11:25
2

Here is a plain-format version too, just for fun:

\def\ealign#1{\def\amp{&}% props to Bruno
  \def\intoalpha##1{\ifcase##1 a\or b\or c\or d\or e\or f\or g\or h\or i\or
    j\or k\or l\or m\or n\or o\or p\or q\or r\or s\or t\ot u\or v\or w\or x\or
    y\or z\else##1\fi} % convert given int < 26 to letter
  \count1=0 % used by plain output for info, let's use it for column count
  \vbox{\openup1\jot % increase (base)lineskip(limit) by 3pt (default)
    \halign to\hsize{% make the horizontal alignment take up full width
      &{\rm\intoalpha{\count1})}\enspace\global\advance\count1 by1% column count
      \mathsurround0pt$\displaystyle##$\tabskip0pt&% every other column resets
      \amp##\tabskip1em plus.5\hsize\crcr#1\crcr}}}% \tabskip to zero, so there
                                                   % is no surplus skip at end

So you see,
$$\ealign{
  \lim_{n\to\infty} {1000n\over n^2+1} &
  \lim_{n\to\infty} \left(\sqrt{n+1}-\sqrt n\,\right) &
  \lim_{n\to\infty} {{\root3\of n}\sin n!\over n+1} \cr
  \lim_{n\to\infty} {(-2)^n+3^n\over(-2)^{n+1}+3^{n+1}}
}$$
and that's that. However, if you'd like to have it indented, you could
$$\tabskip\parindent\ealign{
  \lim_{n\to\infty} {1000n\over n^2+1} &
  \lim_{n\to\infty} \left(\sqrt{n+1}-\sqrt n\,\right) &
  \lim_{n\to\infty} {{\root3\of n}\sin n!\over n+1} \cr
  \lim_{n\to\infty} {(-2)^n+3^n\over(-2)^{n+1}+3^{n+1}}
}$$
is the same thing, only a second time.
\bye

Looks like:
enter image description here

You must log in to answer this question.

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