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 there a way to make something like tabular such that in a loop we get each column in a line and render them in a custom format. Like this

\begin{custom_tabular}
l1c1 & l1c2 & l1c3 \\
l2c1 & l2c2 & l2c3
\end{custom_tabular}

and render the the elements in a custom format, e.g.

\textbf{l1c1}: l1c2$^{l1c3}$

for all the lines. Expected output:

enter image description here

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

You can do this with the collcell package which allows you to pass the entry of each column to a command for further processing:

enter image description here

Below I have defined two new column types. The H column type is for the header column, and the E column type is for the exponent column. The middle column is just a normal l, but with a @{} to remove the column separation between this column and the subsequent column containing the exponent.

References:

A previous answer of mine customize the “cell environment” in a tabular also shows:

  • How to use the array package, which can definitely accommodate the header column with

      \newcolumntype{H}{>{\bfseries}l<{:}}%
    

    but not sure how to get the superscript column to work.

  • A method which does not require any additional packages, by defining a macro to process each row. But, this requires changing each row of the table.

Code:

\documentclass{article}
\usepackage{collcell}

\newcommand{\HeaderColumn}[1]{\textbf{#1:}}
\newcommand{\ExponentColumn}[1]{${}^{#1}$}%

\newcolumntype{H}{>{\collectcell\HeaderColumn}{l}<{\endcollectcell}}
\newcolumntype{E}{>{\collectcell\ExponentColumn}{l}<{\endcollectcell}}

\begin{document}
  \begin{tabular}{H l@{} E}
    l1c1 & l1c2 & l1c3 \\
    l2c1 & l2c2 & l2c3
  \end{tabular}
\end{document}
share|improve this answer
    
Thanks @peter-grill –  anandogc Jul 15 '12 at 10:40
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.