1

I would like to provide a wrapper around tabularx in way to let users define the overall content alignment without defining tabular border style.

Something along lines below. Users can still define column content alignment and spacing (e.g. p columns) and the aforementioned atable environment (should) silently add border styles generating preamble string c|c. In case of a 5 columns table I would have the c|c|c|c|c preamble string.

\documentclass{article}

\usepackage{tabularx}
\usepackage{xparse}

\newenvironment{atable}[2][]
    {%
        \tabularx{\linewidth}{#1}%
        #2 \tabularnewline \hline %
    }
    {\endtabularx}

\begin{document}

\begin{atable}[cX]{Header 1 & Header 2}
    Content 1 & Content 2 \tabularnewline \hline
\end{atable}

\end{document}

The way I was thinking of implementing this was to consider the input preamble string as a list and concatenating each items with the | separator, finally passing the outcome to the tabularx environment.

Despite the vast literature on using for loops and expl3 solutions for dynamic tabular content, I found no post focusing on the making the preamble string modular. I did find tabular environments have some syntax sugar to repeat columns, but that is not what I am looking after.

In particular, I believe the bit I am missing is how to generate a delayed-expandable command generated by a loop expression, with the loop incrementally constructing the preamble string.

I tried to match the expl3 documentation with the examples found on the internet, but I feel at a lost with its syntax and can't really get a grasp on what the solutions found really did.

Could you please point me to the correct approach to achieve what I looking for?

Some more background to make the context clearer. I am currently in the process of writing a custom class that comes with two presentations A and B. I would use the tabularx wrapper to provide consistent tables based on the presentation chosen: for instance presentation A would have all vertical lines between columns, while presentation B would have only external borders.

0

1 Answer 1

1

This sounds like a good use case for the tabularray package, which allows you to control lines/borders separately from the content:

\documentclass{article}

\usepackage{tabularray}

\begin{document}

\SetTblrInner{vline{1,Z}={solid}}

\begin{tblr}{
  colspec={cc}
}
test & test\\
\end{tblr}

\SetTblrInner{vlines}

\begin{tblr}{
  colspec={cc}
}
test & test\\
\end{tblr}

\end{document}

enter image description here

3
  • I am quite hesitant to switch to a new package for tables as tabularx has been integrated into the class i am writing for some time now and can't really spend some more time dealing with possible quirks of the new package. Moreover I was able to replicate the same configuration both to tabularx and xltabular for long tables, so I am even more hesitant to switch. I will consider this answer if no other alternative using the package provided in the mwe comes up.
    – Agodie A
    Commented Dec 7, 2023 at 14:15
  • Hi, I finally gave the tabularray package a try. Definitely helps in keeping things separate and it is quite documented. It definitely has its quirks and now the whole doc takes a couple of minutes to compile rather than a handful of seconds. I am overall happy with this solution and think it will benefit the class I am writing on the long term. Thanks a lot for the suggestion!
    – Agodie A
    Commented Dec 8, 2023 at 13:36
  • @AgodieA Welcome amongst the tabularray users :) Yes, its slowness is a known problem, but it makes it easy to separate form from content. Commented Dec 8, 2023 at 13:38

You must log in to answer this question.

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