# How do I create an align environment without space between cells?

For example, I would like to create a macro to draw a tableau with letters in the cells. First I create a macro to take in a tabular-like data argument, called \tableau, in which I created a \halign environment to parse the data and make it into a matrix of cells, in each cell, I used a \tableaucell macro to draw the cell. I noticed that \halign defaultly create some space between cells, both vertically and horizontally. I managed to eliminate the vertical space by setting the \lineskip to 0pt, but not able to find a way to eliminate the horizontal space too. Here is a simple code to demonstrate my idea.

\documentclass{article}
\usepackage{tikz}

\newcommand\tableau[1]{
\let\\=\cr
\lineskip=0pt
\halign{&\tableaucell{##}\cr#1\cr}
}

\newcommand\tableaucell[1]{
\begin{tikzpicture}
\node at (.5,.5) {\smash{$#1$}};
\draw (0,0)--(0,1)--(1,1)--(1,0)--(0,0);
\end{tikzpicture}
}

\begin{document}
\tableau{a & b \\ c & d & g}
\end{document}


And the result is like:

As you can see there are horizontal space between cells and the vertical space is not really eliminated either. Is there any better solution? The most important thing is that the macro must be able to take a tabular-like data as the argument.

• there are some good packages on ctan for tableaux. go to ctan and search for tableau, then scan the documentation for a package that meets your needs. – barbara beeton Oct 27 '13 at 8:53

A combination of spurious spaces in your definition and tikz: double lines are shifted, the latter solved here in your original code with a overlay-use as bounding box combination and in my proposal with negative row and column separators.

## Code

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\newcommand\tableau[1]{%
\let\\=\cr
\lineskip=0pt
\halign{&\tableaucell{##}\cr#1\cr}}

\newcommand\tableaucell[1]{%
\begin{tikzpicture}
\node[font=\mathstrut, minimum size=+1cm, minimum height=+1cm,
draw, overlay] at (.5,.5) {$#1$};
\path[use as bounding box] (0,0) rectangle (1,1);
\end{tikzpicture}}
\newcommand\tableauTikz{%
\tikz\matrix[
matrix of math nodes,
inner sep=+0pt,
nodes={draw,minimum size=+1cm, minimum height=+1cm, font=\mathstrut},
row sep=+-1\pgflinewidth,
column sep=+-1\pgflinewidth]}
\begin{document}
\tableau{a & b \\ c & d & g}
\bigskip

\noindent
\tableauTikz{a & b \\ c & d & g \\};
% otherwise catcode problems (see ampersand replacement option)
\end{document}


The precise values to be chosen, but a quick attempt to remove horizontal spaces is the following:

\documentclass{article}
\usepackage{tikz}

\newcommand\tableau[1]{
\let\\=\cr
\lineskip=0pt
\halign{&\tableaucell{##}\cr#1\cr}
}

\newcommand\tableaucell[1]{
\begin{tikzpicture}
\node at (.5,.5) {\smash{$#1$}};
\draw (0,0)--(0,1)--(1,1)--(1,0)--(0,0);
\end{tikzpicture}
}

\begin{document}
\tableau{a & b \\ c & d & g}
\end{document}


The horizontal spaces come from the space before and after the tikzpicture environment in the definition of \tableaucell. Vertical spaces can be eliminated with \offinterlineskip. The thick lines (where two lines rub together) can be eliminated with negative \tabskip and negative \vskip between rows:

\documentclass{article}
\usepackage{tikz}

\newcommand\tableau[1]{%
{\tabskip-.4pt % skip back over rule to the left
\let\\=\cr
\everycr{\noalign{\vskip-.4pt}}% skip up over rule above
\offinterlineskip
\halign{&\tableaucell{##}\cr#1\crcr}%
}%
}
\node at (.5,.5) {\smash{$#1$}};

• Why \crcr instead of \cr? – xzhu Oct 28 '13 at 7:42
• @trVoldemort The TeX primitive \crcr is often used in macros. It means \cr, except that it does nothing if it immediately follows a \cr. This prevents an extra blank line if the user ends #1 with a \cr, and acts as a final \cr if the user doesn't. – Dan Nov 8 '13 at 6:25