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.

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

share|improve this question
    
multicol just stops you doing 1 as a sanity check. It would be trivial to define an environment that did ifnum#1=1 \par \let\endmulticols\par \else \multicols{#1} as the begin code and \endmulticols as the end code, if that's what you need. Ie do nothing if 1 column required but switch to multicol if more than 1 column required –  David Carlisle Jul 11 '12 at 13:38
    
If I stick with the multicol environment as opposed to multiple code legs then I still need the multicol environment present even with 1 column since the latex code producing the content within it uses variables from the multicol environment such as \columnwidth, \columnseprule and \columnseprulecolor . –  user1189687 Jul 11 '12 at 13:47
    
If the document has loaded multicol package those will be defined so your code can set them they just wouldn't be used in the 1 col case –  David Carlisle Jul 11 '12 at 13:50

1 Answer 1

up vote 1 down vote accepted

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

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.