How to make table less cramped
Experiment with Mico's solution: The fractions can be made less ragged, if the fraction bars have equal lengths. All numerators and denominators have one or two digits. The macro \mytwofrac
extends the numerator and/or denominator, if there is only one digit. The following example assumes non-proportional widths for the digits and that the width of a digit is 0.5em (for simplicity).
\documentclass{article}
\usepackage{calculator,pgffor,etoolbox}
\usepackage{array} % <-- new
\begin{document}
\newcommand*{\mytwofrac}[2]{%
\frac
{\ifnum#1<10 \kern.25em#1\kern.25em\else#1\fi}%
{\ifnum#2<10 \kern.25em#2\kern.25em\else#2\fi}%
}
\newcommand*\mytable{}
\foreach \i in {1,...,6}{
\foreach \j in {1,...,6}{
\ADD{\i}{\j}\sum
\FRACTIONSIMPLIFY{\sum}{35}\num\div
\xappto\mytable{
(\i,\j)\to\mytwofrac{\num}{\div}&
}
}
\gappto\mytable{\\}
}
\[
\renewcommand\arraystretch{2.25}
\setlength\arraycolsep{4pt} % default: 5pt
\begin{array}{@{} *{6}{>{\displaystyle}l} l @{}}
\mytable
\end{array}
\]
\end{document}
Here's a solution that uses an array
environment instead of a tabular
environment and creates 6 separate left-aligned columns whose contents are automatically in display-math mode.
\documentclass{article}
\usepackage{calculator,pgffor,etoolbox}
\usepackage{array} % <-- new
\begin{document}
\newcommand*\mytable{}
\foreach \i in {1,...,6}{
\foreach \j in {1,...,6}{
\ADD{\i}{\j}\sum
\FRACTIONSIMPLIFY{\sum}{35}\num\div
\xappto\mytable{
(\i,\j)\to\frac{\num}{\div}& % note: no $-symbols necessary
}
}
\gappto\mytable{\\}
}
\[
\renewcommand\arraystretch{2.25}
\setlength\arraycolsep{4pt} % default: 5pt
\begin{array}{@{} *{6}{>{\displaystyle}l} l @{}}
\mytable
\end{array}
\]
\end{document}
Some explanations:
The opening and closing
@{}
particles mean, "no whitespace padding" (at the left- and right-hand edges). (These particles are, strictly speaking, optional. However, I think it's nice to provide them.)*{6}{>{\displaystyle}l}
means, "create 6 columns of type>{\displaystyle}l
", i.e., left-aligned columns whose cells are automatically in display-style math mode. This is useful because\frac
will then generate "large" fractions.The final
l
-type column is a "dummy" column. Its contents are always going to be empty; it's necessary, though, to specify a 7th column, as the(\i,\j)\to\frac{\num}{\div}&
directive inserts a column divider,&
, at the end of each output string. Since there are 6 instances of&
, one must set up 7 (not 6) columns.
Here is a solution with cellspace
, which lets you define minimal vertical spacing at the top and bottom of cells in columns with sprefixezd with the letter S
(or C
if you load siunitx
):
\documentclass{article}
\usepackage{calculator}
\usepackage{nccmath}
\usepackage{pgffor,etoolbox}
\usepackage{cellspace}
\setlength{\cellspacetoplimit}{6pt}
\setlength{\cellspacebottomlimit}{6pt}
\begin{document}
\newcommand*\mytable{}
\foreach \i in {1,...,6}{
\foreach \j in {1,...,6}{
\ADD{\i}{\j}\sum
\FRACTIONSIMPLIFY{\sum}{35}\num\div
\xappto\mytable{
$(\i,\j)\rightarrow\frac\num\div$
}
}
\gappto\mytable{\\}
}
\begin{tabular}{Sc}
\mytable
\end{tabular}
\end{document}