13

I've been frustrated in recent applications with designing tables in LaTeX that have the properties I desire. I can almost always achieve the formatting I want, but a large part of my frustration comes from the fact that every formatting change is ad-hoc or appears like a hack. I am not a fan of this style of LaTeX design.

I was wondering if there is a single package that allows me to create a table environment with the following properties:

  1. I can specify the horizontal and vertical alignments of every row and column, individually.
  2. I can specify the height and width of every row and column, individually, either in terms of fixed lengths or stretching.
  3. Failing to specify one of the above yields a pleasing default behavior similar to the default tabular settings.
  4. The table is capable of spanning multiple pages without breaking.

The ideal formatting for me would be one for which, at the beginning of the environment, one can declare all the relevant spacing and alignment parameters for both rows and columns, and then the body of the table follows. Note that in the default tabular environment, this is true only of the columns; the formatting for each row appears in the body.

11
  • @DavidCarlisle I like the emphasis ...................
    – azetina
    Oct 22, 2013 at 0:36
  • Haha, well, is there anything that can just do the first two? I recognize the difficulties in designing table environments that can work across multiple pages. Oct 22, 2013 at 0:36
  • 4
    @azetina not so much emphasis, just obeying the site rules:-) Oct 22, 2013 at 0:37
  • 1
    I would specify rows in a syntax nearly identical to the column settings in tabular. Just as trying to make more columns than are specified (using too many &'s) breaks the output, specifying too many rows would do the same thing. Oct 22, 2013 at 0:45
  • 3
    have you looked at the pgfplotstable package?
    – cmhughes
    Oct 22, 2013 at 3:35

4 Answers 4

9

The One And Only Tabular Layout Package

You are asking for a package to improve the way to lay out your tabulars. On the German list TEX-D-L recently somebody required help to display data in a special way, depending whether the integer inside a cell differs from a standard value and Herbert Voss came up with a very nice and short solution:

\documentclass[12pt]{article}
\usepackage{array,xcolor}
\def\stripCmd\ignorespaces#1\unskip{#1}
\def\checkVal#1!!{\def\temp{\stripCmd#1}%
   \ifnum\temp>3\textcolor{red}{#1}\else%
     \ifnum\temp<3\textcolor{blue}{#1}\else#1\fi\fi}
\begin{document}

\begin{tabular}{@{} *5{>{\checkVal}c<{!!}} c @{}}
1 & 2 & 3 & 4 & 5 &\\
7 & 5 & 3 & 2 & 3 & \\
\end{tabular}

\end{document}

Tabular with coloured values

Nice, isn't it?

People need very different layouts inside tabulars. They vary much more than the layout of ordinary text does.

So the package that serves your needs won't help others much. So please, give us some examples of the tabulars you'd like to create. Maybe someone here can provide some kind of shortcut.

0
3

As noted by David Carlisle in the comments, the "normal" underlying TeX primitives for this are \halign and \valign, for horizontal alignment and vertical alignment, respectively.

They are used like this:

\[h|v]align{<preamble template(s)>\cr
            <content>\cr}

where # (or, character with \catcode 6) marks the place where the <content> for that column/row will go, and & (or, character with \catcode 4) divides columns/rows, both in the <preamble>, and in the <content>.

\halign puts the <content>s into \hboxes, while \valign puts them in \vboxes.

Unfortunately they cannot be combined (at least to my knowledge); so while with \halign you can define individual column templates, and with \valign individual row templates, you can't use them both at the same time.

So the "normal" underlying primitives fail on points 1) and 2), while 3) depends on the given <preamble template>. 4) should be covered, though.

If ConTeXt is an option, you could have a look at the TABLE, and other table typesetting possibilities.

1
  • Thanks for the info about \halign and \valign. I don't think I'll be switching from basic LaTeX any time soon, however. Oct 24, 2013 at 18:23
2

I'd suggest my cals package, which support decorations by design. Although it does not fit your request completely, you might find it useful. Examples of use.

2

All these four properties are easy peasy with tblr environment in LaTeX3 package tabularray.

  1. I can specify the horizontal and vertical alignments of every row and column, individually.
\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{colspec={Q[l]Q[c]Q[r]},rowspec={|Q[t]|Q[m]|Q[b]|}}
 {Alpha \\ Alpha} & Beta               & Gamma \\
 Delta            & Epsilon            & {Zeta \\ Zeta}  \\
 Eta              & {Theta \\ Theta}   & Iota  \\
\end{tblr}
\end{document}

enter image description here

  1. I can specify the height and width of every row and column, individually, either in terms of fixed lengths or stretching.
\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{hlines,vlines,row{1-3}={7mm},column{1-4}={15mm,c}}
 Alpha   & Beta  & Gamma   & Delta \\
 Epsilon & Zeta  & Eta     & Theta \\
 Iota    & Kappa & Lambda  & Mu    \\
\end{tblr}
\end{document}

enter image description here

  1. Failing to specify one of the above yields a pleasing default behavior similar to the default tabular settings.
\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{}
 Alpha   & Beta  & Gamma   & Delta \\
 Epsilon & Zeta  & Eta     & Theta \\
 Iota    & Kappa & Lambda  & Mu    \\
\end{tblr}
\end{document}
  1. The table is capable of spanning multiple pages without breaking.

This property was added into tabularray package in version 2021L.

You must log in to answer this question.

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