[Tex/LaTex] Multicol alternative

multicoltables

This post is a follow up to this post:
multiple pairs of columns
which was about generating columns of name/value pairs. There are sample outputs there. I now have several solutions and am at the point of figuring out what is best and whether there are any implementation alternatives.

This is more about finding packages to implement solutions than generating solutions since I already have several working solutions prototyped but at any rate here are several criteria:

  • have decided to generate this from a program so it should be amenable to that
  • need lines between rows and columns so the solution must be sufficiently customizable
  • happy tradeoff between leveraging latex functionality and keeping both the
    latex code and the program code which generates it simple
  • readable generated latex code
  • can handle varying widths of names and values
  • runs fast
  • can handle a single column of name/value pairs in addition to multiple columns

Thanks to a number of respondents plus a few of my own tests I now have quite a
few possible solutions some of which can be seen at the above link. There are
undoubtedly other solutions too. They seem to fall in these categories:

  • tikz based solution
  • make each name/value pair a one row table and put these tables in a multicol or nested table
  • make each column of name/value pairs a table and but them in a multicol or nested table

I was favoring one table per column in a multicol since it was reasonably simple and automatically can handle varying widths of names and values per column but I came across a snag that multicol does not allow one column (I tried it and it gave me a message that it was going to use 2 columns despite the fact that I specified 1) so I would have to write the program twice: once with multicol and once for one column tables. Although nested tables seems a bit more work than multicol I am now thinking of moving to that since it allows all cases to fit in the same framework and so would be overall simpler.

Question: What I was wondering was whether there are any alternatives to multicol that can handle a single column and the other criteria. I have done quite a bit of searching but did not find anything suitable so far but thought I would post this in case someone else knows of something before I give up on that approach and move to the slightly more complex nested tables.

EDIT: Here is the code for a tabu table for each column within a multicol. It works for two or more columns but not one.

\documentclass{article}
\usepackage{multicol}
\usepackage{tabu}
\usepackage[table]{xcolor}

\begin{document}


\providecommand{\Column}[1]{}
\renewcommand{\Column}[1]{%
    \begin{tabu} to \columnwidth{>{\bfseries}lX}%
    \everyrow{\tabucline[blue]-}%
    #1%
    \end{tabu}%
}

\begin{center}\small
\setlength{\columnseprule}{.4pt}
\renewcommand\columnseprulecolor{\color{blue}}
\begin{multicols}{2}

\Column{
    Name1 & Value1. \\
    Name2 & Value2. \\
    Name3 & Value3. \\
}
\Column{
    Name4 & Value4. \\
    Name5 & Value5. \\
}

\end{multicols}
\end{center}

\end{document}

which looks like this:

screenshot

Best Answer

As noted in comments you could define an environment that does nothing if passed 1 but uses multicols otherwise:

\newenvironment{mymcol}[1]
  {\ifnum#1=1 
   \let\endmulticols\par
   \def\multicols##1{\par}%
   \fi
   \begin{multicols}{#1}}%
   {\end{multicols}}
\makeatother

\begin{mymcol}{2}

\Column{
    Name1 & Value1. \\
    Name2 & Value2. \\
    Name3 & Value3. \\
}
\Column{
    Name4 & Value4. \\
    Name5 & Value5. \\
}

\end{mymcol}