2

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

0

2 Answers 2

5

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}
0
1

This is exactly what \halign TeX primitive does.

\halign{{\bf#\unskip}: &#\unskip&$^{#}$\cr
l1c1 & l1c2 & l1c3 \cr
l2c1 & l2c2 & l2c3 \cr
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .