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 have a table resembling a matrix with a extra lines for emphasis. This table may also contain frac{} items which do fit into the cell but sort of "hit" the boundaries.

Trouble is, that I have quite a few of those tables. Is there an easy way to increase the padding for all of those tables? Possibly without touching every single table?

A picture illustrating the issue: Notice how eg (x5|x3) looks odd

The source for this looks like this:

\begin{tabular}{c||c|c|c||c|c|c|c||c|c}
        & $x_1$ & $x_2$ & $x_3$            & $x_4$           & $x_5$ & $x_6$ & $x_7$ & RS     & Q     \\ \hline \hline
  $x_2$ & 0     & 1     & $\frac{1}{3}$    & $\frac{1}{3}$   & 0     & 0     & 0     & 50     & 150   \\ \hline
  $x_5$ & 0     & 0     & $\frac{5}{6}$    & $-\frac{2}{3}$  & 1     & 0     & -0.5  & 20     & 24    \\ \hline
  $x_6$ & 0     & 0     & $\frac{1}{12}$   & $-\frac{2}{3}$  & 0     & 1     & -0.25 & 25     & 300   \\ \hline
  $x_1$ & 1     & 0     & 0.25             & 0               & 0     & 0     & 0.25  & 25     & 100   \\ \hline \hline
  $-z$  & 0     & 0     & $\frac{79}{120}$ & $\frac{23}{30}$ & 0     & 0     & -0.575& -172.5 &
\end{tabular}
share|improve this question

3 Answers 3

up vote 9 down vote accepted

The possibility of changing the multiplicative parameter \arraystretch has already been mentioned in another answer. For the sake of completeness, I think it's useful to also mention the additive parameter \extrarowheight, which one would use as follows:

\usepackage{array}
\setlength\extrarowheight{2pt} % or whatever amount is appropriate

If you include these commands in the document's preamble, all array and tabular environments will be affected by them.

I can't help but comment on some additional aspects of your table. First, all those horizontal and vertical lines make it look very busy but probably don't add all that much to its readability. I'd therefore suggest getting rid of all single-vertical and single-horizontal lines and change all double lines to single lines. Second, when you have numerical information in the table, it's really important to align the numbers in ways that makes reading them easy. For instance, numbers with decimal points should be aligned on the decimal point; and if some numbers are negative and some are positive, it's helpful to align them in ways that emphasizes that fact.

Here, then, is how I'd suggest you render the table:

enter image description here

\documentclass{article}
\usepackage{dcolumn}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\setlength{\extrarowheight}{2pt}
\setlength{\arraycolsep}{5pt}
\begin{document}
$
\begin{array}{c|c c c|r c c d{3}|d{1} d{0} @{}}
    & x_1 & x_2 & x_3 & x_4 & x_5 & x_6 & x_7 & RS & Q \\ \hline 
x_2 & 0 & 1 & \frac{1}{3}  &  \frac{1}{3} & 0 & 0 &  0    & 50 & 150\\ 
x_5 & 0 & 0 & \frac{5}{6}  & -\frac{2}{3} & 1 & 0 & -0.5  & 20 & 24 \\ 
x_6 & 0 & 0 & \frac{1}{12} & -\frac{2}{3} & 0 & 1 & -0.25 & 25 & 300\\ 
x_1 & 1 & 0 & 0.25         & 0          & 0 & 0 &  0.25 & 25 & 100\\ \hline
-z  & 0 & 0 & \frac{79}{120} & \frac{23}{30} & 0 & 0 & -0.575 & -172.5 & \\
\end{array}
$
\end{document}
share|improve this answer
    
Looking at your example I must admit that you are defnitely correct. And another thumb up for your example of \newcolumntype{}, I never came across that command. –  Marcus Riemer Jul 26 '12 at 17:37

If you use the \arraystretch parameter in the preamble then all tables are going to obey that setting as follows

\documentclass{article}
\renewcommand{\arraystretch}{1.5}
\begin{document}
\begin{table}%
\centering
\begin{tabular}{c||c|c|c||c|c|c|c||c|c}
        & $x_1$ & $x_2$ & $x_3$            & $x_4$           & $x_5$ & $x_6$ & $x_7$ & RS     & Q     \\ \hline \hline
  $x_2$ & 0     & 1     & $\frac{1}{3}$    & $\frac{1}{3}$   & 0     & 0     & 0     & 50     & 150   \\ \hline
  $x_5$ & 0     & 0     & $\frac{5}{6}$    & $-\frac{2}{3}$  & 1     & 0     & -0.5  & 20     & 24    \\ \hline
  $x_6$ & 0     & 0     & $\frac{1}{12}$   & $-\frac{2}{3}$  & 0     & 1     & -0.25 & 25     & 300   \\ \hline
  $x_1$ & 1     & 0     & 0.25             & 0               & 0     & 0     & 0.25  & 25     & 100   \\ \hline \hline
  $-z$  & 0     & 0     & $\frac{79}{120}$ & $\frac{23}{30}$ & 0     & 0     & -0.575& -172.5 &
\end{tabular}
\caption{Some table}
\label{tab:1}
\end{table}
\end{document}

enter image description here

To keep this change local, you can simply place it in the table environment instead of the preamble, say, just after the \centering command. This would cause a temporary change in the global settings.

share|improve this answer
    
Thanks for your explanation. Especially the remark on how to set override the setting "locally". –  Marcus Riemer Jul 26 '12 at 12:10

http://www.tex.ac.uk/cgi-bin/texfaq2html?label=struttab discusses the problem.

it mentions booktabs.sty, cellspace.sty, makecell.sty and tabls.sty

you do of course make the problem look "super-bad" by having all those horizontal rules. the docs of booktabs explain why those aren't as good a thing as Lamport seems to imagine in the latex book.

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.