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.

I want to TeXify this document as an exercise. At the bottom of its second page, there are some tables. I tried to create something similar to this using LaTeX and finally did this:

Von den 15 Zerlegungen \emph{bei} $\mu=4$ sind die ersten sieben:
\begin{flushleft}
$v=2;\ p=
\begin{tabular}[t]{|c|c|}\hline
$-1$&$-256$\\\hline
\end{tabular}$
[bedeutet: $(-1)^2+(-256)^2=p$]\\
$v=3;\ p=
\begin{tabular}[t]{|c|c|}\hline
$255$&$0$\\\hline
$-16$&$-16$\\\hline
\end{tabular}$
\end{flushleft}

To me, that code seems very strange and it doesn't works. Can some TeXpert help me please?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted
\usepackage{array}
...

Von den 15 Zerlegungen \emph{bei} $\mu=4$ sind die ersten sieben:
\begin{flushleft}
$v=2$; $p=
\begin{array}[t]{|c|c|}
\firsthline
-1&-256\\
\lasthline
\end{array}$
[bedeutet: $(-1)^2+(-256)^2=p$]\\
$v=3$; $p=
\begin{array}[t]{|c|c|}
\firsthline
255&0\\
\hline
-16&-16\\
\lasthline
\end{array}$
\end{flushleft}

In these particular examples \lasthline is not really necessary; but it's handy to put it there, so if we change our mind and want bottom alignment all we need is to change the optional argument to array. These commands work, of course, also for tabular. They won't do any good if the first table row has excessive height.

Some advices. Use array in math mode, it spares you from putting so many $ symbols. Notice also the $ before the semicolon: different formulas should be segregated on their own.

share|improve this answer
    
Good advice! Btw. there's further \lasthline, useful if bottom alignment is desired. –  Stefan Kottwitz Jun 25 '11 at 21:03
    
@Stefan: I'll add \lasthline, thanks. –  egreg Jun 25 '11 at 21:05
    
@egreg Another little question: How can I get the columns to have all the same size? –  FUZxxl Jun 25 '11 at 21:33
1  
For that you need the p specifier and fix the width yourself. Or use \makebox[\widthof{$-256$}]{$-1$} (requires the calc package). –  egreg Jun 25 '11 at 21:43
1  
That's normal. But you can say >{\centering\arraybackslash$}p{1cm}<{$} and get fixed width columns with centered math mode entry. –  egreg Jun 25 '11 at 22:15
show 1 more comment

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.