I have a tabular array that is based on David Carlisle's answer to Generating LaTeX tabular code during compilation. I have modified the code so that columns and rows are defined in different \newcommand command definitions (practically lists). \regionlist contains brain regions {ABC,DEF,GHI} and \contrastlist contains 'contrasts' or activities {SLEEP,RUN,SPEAK}. These are defined in g_loc_contrast_tabular_def.tex. The data for the cells is defined in g_loc_contrast_def.tex using \def macro definitions, one for each data cell of the tabular array, excluding the top row and the left-most column.

So this particular array contains data on localized neural activity in different situations, the situations are on rows, brain regions on columns, and the data are defined by macros such as \def\locBABCcontrastSLEEP{both ABCs during sleep}. These definitions work fine.

I have added code to replace row headers with their descriptions that are defined in g_loc_contrast_def.tex using \def macros (\contrastdescSLEEP, \contrastdescRUN, \contrastdescSPEAK), but I have not been able to get the visual output right. On the leftmost column, I want "deep sleep" on the 1st data row (2nd row), "running marathon" on the 2nd data row (3rd row), and "speaking" (all with bold, without quotes), but I get LEEP deep sleep SSLEEP", "UN running marathon RRUN" and "PEAK speaking SSPEAK" (without quotes). The strings RUN, SLEEP and SPEAK are used in macro names, and when I finally found out a way to get the description in the array by using \textbf{\newcommand\contrastdesc#1{\csname contrastdesc#1\endcsname} \contrastdesc#1}%, the first letter of the #1 string, that holds the row-code (SLEEP, RUN or SPEAK), was moved to the right side of the description string together with complete row-code string. So I'm trying to find out what is wrong with my LaTeX code to get the output right.

I'm total beginner in LaTeX macros, so it might be just some basic mistake. I have tried to find a solution and to understand LaTeX macro system, but I think I understand still only a tiny bit of it.

The code compiles without problems by using latexmk --pdf main.tex.




% listheadings.

% xlistheadings.

% listbody.

% xlistbody.
\textbf{\newcommand\contrastdesc#1{\csname contrastdesc#1\endcsname}

% xlistdata.
&\csname locB#1contrast\thisrow\endcsname

% preamble.

% tablestart.

\def\locBABCcontrastSLEEP{ both ABCs during sleeping }
\def\locBABCcontrastRUN{ both ABCs during running }
\def\locBABCcontrastSPEAK{ both ABCs during speaking }

\def\locBDEFcontrastSLEEP{ both DEFs during sleeping }
\def\locBDEFcontrastRUN{ both DEFs during running } 
\def\locBDEFcontrastSPEAK{ both DEFs during speaking }

\def\locBGHIcontrastSLEEP{ both GHIs during sleeping }
\def\locBGHIcontrastRUN{ both GHIs during running } 
\def\locBGHIcontrastSPEAK{ both GHIs during speaking }

\def\contrastdescSLEEP{ deep sleep }
\def\contrastdescRUN{ running marathon }
\def\contrastdescSPEAK{ speaking }

} % end scalebox
\caption{Caption goes here.}
    \item Item number one. 
    \item Item number two.





1 Answer 1


I think you just want

\textbf{\csname contrastdesc#1\endcsname}%

enter image description here


You must log in to answer this question.

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