Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is it possible to improve the alignment of the first item?

\documentclass{article}

\begin{document}

\begin{enumerate}
\item  \begin{tabular}{cccccccccc}
   $x[n] = $ & \{1/3 & -1/2 & 1/4 & -1/8 & 1/6\} & and\\
      &   &   & $\uparrow$   &   &  &  \\   
  \end{tabular}
\begin{tabular}{cccccccccc}
   $h[n] = $ & \{1 & -1 & 1 & -1\} \\
             &    &   &    &   &    &    \\   
  \end{tabular}
\item \begin{tabular}{cccccccccc}
   $x[n] = $ & \{1 & -2 & -3 & 0 & -1\} & and\\  
  \end{tabular}
\begin{tabular}{cccccccccc}
   $h[n] = $ & \{2 & -1/2 & -3 & 1 & -2\} \\
  \end{tabular}
\end{enumerate}

\end{document}

The result is:

enter image description here

share|improve this question
1  
When you have a whole bunch of similarly-aligned tabular columns, use the *{<num>}{<type>} notation. In your case, \begin{tabular}{*{10}{c}}. It's easier to debug and more readable. Also, consider keeping the numerals in math mode, which provides a consistent spacing around the unary operator -. –  Werner May 16 '13 at 1:33
    
What do you want the $\uparrow$ to point from and to? –  Pål GD May 16 '13 at 9:24
    
The \upparrow is a "n = 0" mark. –  Papiro May 16 '13 at 9:28

4 Answers 4

up vote 11 down vote accepted

If I understand correctly, you need to add [t] alignment:

\documentclass{article}

\begin{document}

\begin{enumerate}
\item  \begin{tabular}[t]{cccccccccc}        %%%% note [t] here.
   $x[n] = $ & \{1/3 & -1/2 & 1/4 & -1/8 & 1/6\} & and\\
      &   &   & $\uparrow$   &   &  &  \\
  \end{tabular}
\begin{tabular}[t]{cccccccccc}               %%%% and here.
   $h[n] = $ & \{1 & -1 & 1 & -1\} \\
             &    &   &    &   &    &    \\
  \end{tabular}
\item \begin{tabular}{cccccccccc}
   $x[n] = $ & \{1 & -2 & -3 & 0 & -1\} & and\\
  \end{tabular}
\begin{tabular}{cccccccccc}
   $h[n] = $ & \{2 & -1/2 & -3 & 1 & -2\} \\
  \end{tabular}
\end{enumerate}

\end{document}

enter image description here

share|improve this answer

The following is a suggestion for a slightly easier notation that is more flexible. Moreover, it provides a consistent and accurate spacing around the math operators you use:

enter image description here

\documentclass{article}
\usepackage{amsmath,xparse}% http://ctan.org/pkg/{amsmath,xparse}
\NewDocumentCommand\printarray{O{~~} >{\SplitList{,}}m}
{%
  \def\itemdelim{\def\itemdelim{#1}}% Define list separator with one delay
  \ProcessList{#2}{\myitem}% Process list
}
\newcommand\myitem[1]{\itemdelim{#1}}
\begin{document}

\begin{enumerate}
  \item $x[n] = \{\printarray{1/3,-1/2,\underset{\uparrow}{1/4},-1/8,1/6}\}$ and $h[n] = \{\printarray{1,-1,1,-1}\}$
  \item $x[n] = \{\printarray{1,-2,-3,0,-1}\}$ and $h[n] = \{\printarray{2,-1/2,-3,1,-2}\}$
\end{enumerate}

\end{document}

The "array" is printed using \printarray[<sep>]{<CSV list>} where <sep> defaults to ~~.

Delayed definition of the list separator stems from Package xparse \SplitList last token (or originally Cunning (La)TeX tricks), while amsmath provides \underset.

share|improve this answer

I also would like to suggest you another approach, using a matrix environment instead of a tabular; it's more natural, gives you the desired vertical alignment automatically, and saves you the column format specification:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{enumerate}
\item 
$
x[n] = 
\{\begin{matrix} 
1/3 & -1/2 & \smash{\underset{\uparrow}{1/4}} & -1/8 & 1/6
\end{matrix}\} 
$\quad
and\quad 
$
h[n] =
\{\begin{matrix} 
1 & -1 & 1 & -1
\end{matrix}\}
$
\item 
$
x[n] = 
\{\begin{matrix}
1 & -2 & -3 & 0 & -1
\end{matrix}\}
$\quad
and\quad 
$
h[n] =
\{\begin{matrix}
2 & -1/2 & -3 & 1 & -2
\end{matrix}\}
$
\end{enumerate}

\end{document}

enter image description here

share|improve this answer
    
it also applies math mode automatically, which makes the minus signs behave properly without having to think about them. –  barbara beeton May 16 '13 at 12:25

This might be considered cheating, but if you skip the enumeration environment and put everything in one table, things behave better:

\documentclass{article}
\begin{document}
\begin{tabular}{lcccccccccccccccccccc}
1.&$x[n]=$&\{1/3&-1/2&1/4&-1/8&1/6\}& and $h[n]=$&\{1&-1&1&-1\}\\
&&&&&$\uparrow$&&&&&&&&\\
2.&$x[n]=$&\{1&-2&-3&0&-1\}& and $h[n]=$&\{2&-1/2&-3&1&-2\}\\
\end{tabular}
\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.