1

I am trying to make a macro for the rows in my table, just to make it look a bit more elegant. However, the document fails to compile when I use more than one row.

Here's the code I'm trying to duplicate:

\usepackage{tabularx}

\begin{tabularx}{\textwidth}{ r X }
  \bfseries{Topic1:} & Item1, Item2, Item3 \\
  \bgseries{Topic2:} & Item1, Item2, Item3 \\
\end{tabularx}

And my attempt to create a macro:

\usepackage{tabularx}

\begin{tabularx}{\textwidth}{ r X }
  \newcommand{\row}[2]{\bfseries{#1:} & #2 \\}
  \row{Topic1}{Item1, Item2, Item3}
  \row{Topic2}{Item1, Item2, Item3}
\end{tabularx}

And the compiler error I'm getting is "Undefined control sequence." Is there any way to get this to work?

closed as off-topic by Phelype Oleinik, Andrew, Mensch, siracusa, barbara beeton Jun 14 at 1:04

  • This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    Table cells create groups, so definitions made inside a tabular cell don't make it until the next one. Move the definition outside the table. – Phelype Oleinik Jun 13 at 23:05
  • Wow that was embarrassingly easy, thanks! – djorna Jun 13 at 23:08
  • 1
    Don't worry, everyone did that at least once :-) Also note that your usage of \bfseries is incorrect. \bfseries doesn't take an argument and changes the font until the current group ends, so you should use as {\bfseries #1:}. Alternatively, use \textbf, which does take an argument: \textbf{#1:}. By the way, welcome to TeX.SX! – Phelype Oleinik Jun 13 at 23:11
  • 5
    I'm voting to close this question as off-topic because it was solved by moving the definition outside the table. – Phelype Oleinik Jun 13 at 23:11
  • Fair enough, thanks for your help. – djorna Jun 13 at 23:13

Browse other questions tagged or ask your own question.