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.

Is it possible to draw tables as those in Figures below. Tables should have square cells and notations along borders.

I know that I could use the TAB environment from the Easytable package to create square cells tables, but I do not know how to put notations over the top border. I would like to use the multicolumn command for Figure 2 but it does not work in the TAB environment. Or maybe there is another simple approach to achieve the same?

There is and alternative to TAB from the Easytable package as suggested by this link http://www.tug.org/pracjourn/2005-2/robertson/, but I cannot insert any notations and the command multicolumn does not work. I use XeLaTeX.

Table with square cells and notations along vertical and horizontal border.

share|improve this question
    
I'm a bit confused by this. You say that the tables should have square cells but figure 2 does not satisfy this condition. Is the problem that it does not have square cells? Or are square cells not really the point? –  cfr Jan 2 at 16:49
add comment

2 Answers

Solution Ideas

The solution provided here is without any package or anything like that. I strongly suggest that you go for such solutions before you start using any package. You should know what you are doing.

(See the end of this post for a solution which uses the square cell technique from your provided link.)

  1. Your first table actually contains four columns, one with a rule at its right, then three ruled ones.

  2. The notations along borders are actually part of the table. Special type of cells are used here. See the next two enumerations.

  3. For the notations at the top, you use \multicolumn. The cells span one column, have centered contents and are without borders (\multicolumn{1}{c}). We define a macro (\mca) since we use them a number of times.

  4. For notations at the left, again you use \multicolumn. The cells span one column, have centered contents, with border at right (\multicolumn{1}{c|}). Again, we define a macro (\mcb) since we use them a number of times.

  5. You use \cline to span a horizontal line from column 2 to column 4 in the first table.

  6. The second table is a simpler one with three columns. We reuse the macro \mca for this one as well.

  7. You tweak \arraystretch to adjust row heights (to get the square cells as asked by you).

I am pretty sure that you know how to put these tables inside float environments.


The Code

\documentclass{article}

\begin{document}

\def\mca#1{\multicolumn{1}{c}{#1}}
\def\mcb#1{\multicolumn{1}{c|}{#1}}
\renewcommand{\arraystretch}{2.25}
\begin{tabular}{c|c|c|c|}
  \mca{}  & \mca1 & \mca2 & \mca3 \\\cline{2-4}
  \mcb1   & AB    & BC    & DA    \\\cline{2-4}
  \mcb2   & EF    & GH    & IJ    \\\cline{2-4}
  \mcb{C} & KL    & MN    & OP    \\\cline{2-4}
\end{tabular}

\bigskip
\renewcommand{\arraystretch}{2.0}
\begin{tabular}{|c|c|c|}
  \mca{3 bit} & \mca{1-2 bits} & \mca{0 bit} \\\hline
  1           & 10             & 1           \\\hline
\end{tabular}

\end{document}

The Output

enter image description here

Solution Using Your Provided Link

If you insist on using the technique from your provided link, here is an alternate solution for the first table. This uses the square cell technique from the link.

\documentclass{article}

\usepackage{calc}
\usepackage{array}

\newlength\celldim
\setlength\celldim{3em}
\newlength\fontheight
\settoheight\fontheight{A}
\newlength\extraheight
\setlength\extraheight{\celldim - \fontheight}

\makeatletter
\newcolumntype{S}
{ @{}
>{\centering\arraybackslash}
p{\celldim}
<{\rule[-0.5\extraheight]{0pt}%
{\fontheight + \extraheight}}
@{} }
\makeatother

\begin{document}

\def\mca#1{\multicolumn{1}{c}{#1}}
\def\mcb#1{\multicolumn{1}{c|}{#1}}
\begin{tabular}{c|S|S|S|}
  \mca{}  & \mca1 & \mca2 & \mca3 \\\cline{2-4}
  \mcb1   & AB    & BC    & DA    \\\cline{2-4}
  \mcb2   & EF    & GH    & IJ    \\\cline{2-4}
  \mcb{C} & KL    & MN    & OP    \\\cline{2-4}
\end{tabular}

\end{document}

Second Output

enter image description here

share|improve this answer
add comment

You can nest the tabular environments. All cells are 2cm x 2cm:

\documentclass[border=20pt]{standalone}
\usepackage{array}
\usepackage[thinlines]{easytable}
\newcommand\ML[1]{\llap{#1\quad}}

\begin{document}

\huge
\begin{tabular}{c}
\begin{TAB}(e,2cm,2cm){ccc}{ccc}   
     1 & 2 & 3 
\end{TAB}\\[-\normalbaselineskip]
\begin{TAB}(e,2cm,2cm){|c|c|c|}{|c|c|c|}   
\ML{1}AB & BC & DA    \\
\ML{2}EF & GH & IJ    \\
\ML{C}KL & MN & OP    \\
\end{TAB}
\end{tabular}

\end{document}

enter image description here

share|improve this answer
add 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.