0

Suppose I have a command \newcommand{\mycommand}[1]{...}. In particular this :Good way to circle text

Now I want to do some thing like this :

\begin{tabularx}{\textwidth}{X|c}
Some long piece of text & \mycommand{Something}\\
Some long piece of text & \mycommand{Something}\\
Some long piece of text & \mycommand{Something}
\end{tabularx}

How do I do this without having to type \mycommand{...} for all cells in that column.

I have found >{...} for font styles and alignment but I don't know if something like this can be done.

EDIT : I would also like to know if \mycommand can have multiple arguments.

  • 1
    Welcome to TeX.SE. Your question doesn't appear to be related to the tabularx package per se. It could pertain to any column type, in tabular, tabular*, and many other tabular-like environments, right? Please clarify. – Mico Jul 02 '20 at 13:19
  • Yes any. I need my actual document like that. – Siddharth Jul 02 '20 at 13:23
  • Please edit the title and body of your query to focus on what is actually required. – Mico Jul 02 '20 at 13:37
  • You still have a reference to tabularx in the title of your posting, and \begin{tabularx}{X|c} is bound to generate a syntax error since the all-important desired-width argument is missing. (Did you mean to write \begin{tabularx}{\textwidth}{X|c}?) The more extraneous stuff is eliminated, the easier it will be for readers to focus on what's relevant. – Mico Jul 02 '20 at 13:41
  • You can see the collcell package. – Bernard Jul 02 '20 at 14:10
  • Thanks. Could you please provide some easy examples. I don't know much about latex macros. @Bernard – Siddharth Jul 04 '20 at 03:00

1 Answers1

0

Here is a demo with the \Circled command (from circledsteps), using the collcell package: T, defined a new C column type, which collects the contents of each cell of the column, andexcutes the \Circled macro on this contents:

\documentclass[a4paper]{article}

\usepackage{tabularx} \usepackage{collcell} \usepackage{caption} \captionsetup{font = footnotesize} \usepackage{circledsteps} \newcolumntype{C}{>{\collectcell\Circled}c<{\endcollectcell}}

\begin{document} \setlength{\extrarowheight}{3pt}

\begin{tabularx}{\textwidth}{X|C} Some long piece of text & Something \ Some very long piece of text & Something \ Some still quite longer piece of text & Something \end{tabularx}

\end{document}

enter image description here

Bernard
  • 271,350