Skip to main content
added 1434 characters in body
Source Link
Skillmon
  • 77.8k
  • 2
  • 87
  • 152

Using L3's \clist_map_inline:nn instead of forarray this works as intended. The issue is that each line in \makecell forms a cell in a nested tabular, and hence is a group. It seems the loop of forarray doesn't cope with that well.

\documentclass{article} \usepackage{makecell} \ExplSyntaxOn \NewDocumentCommand \listcontacts { m } { \clist_map_inline:nn {#1} { \scriptsize \textbf {##1} \\ } } \ExplSyntaxOff \begin{document} \begin{tabular}{ r r } \hline \textbf{NAME} & \textbf{CONTACT} \\ \hline John Doe & \makecell[r]{\listcontacts{Number One,Number Two,Number Three}} \\ % Error: Tried to expand an \endforeachtoken. Something is wrong. \hline \end{tabular} \listcontacts{Number One,Number Two,Number Three} % renders fine \end{document} 

But this way we get an additional \\ at the end, which causes \makecell to display an empty line at the bottom. To get rid of that we need to treat the first row differently from the others (or the last row, but that would be harder to implement). Additionally, if you use your macro as it is outside of a tabular the \scriptsize would leak and affect the other stuff, so we put it into the argument of \textbf to keep it local.

Everything sticked together looks like this:

\documentclass{article} \usepackage{makecell} \ExplSyntaxOn \seq_new:N \l_strikeagainst_contacts_seq \NewDocumentCommand \listcontacts { m } { \seq_set_from_clist:Nn \l_strikeagainst_contacts_seq {#1} \seq_pop_left:NNT \l_strikeagainst_contacts_seq \l_tmpa_tl { \textbf { \scriptsize \l_tmpa_tl } \seq_map_inline:Nn \l_strikeagainst_contacts_seq { \\ \textbf { \scriptsize ##1 } } } } \ExplSyntaxOff \begin{document} \begin{tabular}{ r r } \hline \textbf{NAME} & \textbf{CONTACT} \\ \hline John Doe & \makecell[r]{\listcontacts{Number One,Number Two,Number Three}} \\ % Error: Tried to expand an \endforeachtoken. Something is wrong. \hline \end{tabular} \listcontacts{Number One,Number Two,Number Three} % renders fine \end{document} 

enter image description here

Using L3's \clist_map_inline:nn instead of forarray this works as intended. The issue is that each line in \makecell forms a cell in a nested tabular, and hence is a group. It seems the loop of forarray doesn't cope with that well.

\documentclass{article} \usepackage{makecell} \ExplSyntaxOn \NewDocumentCommand \listcontacts { m } { \clist_map_inline:nn {#1} { \scriptsize \textbf {##1} \\ } } \ExplSyntaxOff \begin{document} \begin{tabular}{ r r } \hline \textbf{NAME} & \textbf{CONTACT} \\ \hline John Doe & \makecell[r]{\listcontacts{Number One,Number Two,Number Three}} \\ % Error: Tried to expand an \endforeachtoken. Something is wrong. \hline \end{tabular} \listcontacts{Number One,Number Two,Number Three} % renders fine \end{document} 

Using L3's \clist_map_inline:nn instead of forarray this works as intended. The issue is that each line in \makecell forms a cell in a nested tabular, and hence is a group. It seems the loop of forarray doesn't cope with that well.

\documentclass{article} \usepackage{makecell} \ExplSyntaxOn \NewDocumentCommand \listcontacts { m } { \clist_map_inline:nn {#1} { \scriptsize \textbf {##1} \\ } } \ExplSyntaxOff \begin{document} \begin{tabular}{ r r } \hline \textbf{NAME} & \textbf{CONTACT} \\ \hline John Doe & \makecell[r]{\listcontacts{Number One,Number Two,Number Three}} \\ % Error: Tried to expand an \endforeachtoken. Something is wrong. \hline \end{tabular} \listcontacts{Number One,Number Two,Number Three} % renders fine \end{document} 

But this way we get an additional \\ at the end, which causes \makecell to display an empty line at the bottom. To get rid of that we need to treat the first row differently from the others (or the last row, but that would be harder to implement). Additionally, if you use your macro as it is outside of a tabular the \scriptsize would leak and affect the other stuff, so we put it into the argument of \textbf to keep it local.

Everything sticked together looks like this:

\documentclass{article} \usepackage{makecell} \ExplSyntaxOn \seq_new:N \l_strikeagainst_contacts_seq \NewDocumentCommand \listcontacts { m } { \seq_set_from_clist:Nn \l_strikeagainst_contacts_seq {#1} \seq_pop_left:NNT \l_strikeagainst_contacts_seq \l_tmpa_tl { \textbf { \scriptsize \l_tmpa_tl } \seq_map_inline:Nn \l_strikeagainst_contacts_seq { \\ \textbf { \scriptsize ##1 } } } } \ExplSyntaxOff \begin{document} \begin{tabular}{ r r } \hline \textbf{NAME} & \textbf{CONTACT} \\ \hline John Doe & \makecell[r]{\listcontacts{Number One,Number Two,Number Three}} \\ % Error: Tried to expand an \endforeachtoken. Something is wrong. \hline \end{tabular} \listcontacts{Number One,Number Two,Number Three} % renders fine \end{document} 

enter image description here

Source Link
Skillmon
  • 77.8k
  • 2
  • 87
  • 152

Using L3's \clist_map_inline:nn instead of forarray this works as intended. The issue is that each line in \makecell forms a cell in a nested tabular, and hence is a group. It seems the loop of forarray doesn't cope with that well.

\documentclass{article} \usepackage{makecell} \ExplSyntaxOn \NewDocumentCommand \listcontacts { m } { \clist_map_inline:nn {#1} { \scriptsize \textbf {##1} \\ } } \ExplSyntaxOff \begin{document} \begin{tabular}{ r r } \hline \textbf{NAME} & \textbf{CONTACT} \\ \hline John Doe & \makecell[r]{\listcontacts{Number One,Number Two,Number Three}} \\ % Error: Tried to expand an \endforeachtoken. Something is wrong. \hline \end{tabular} \listcontacts{Number One,Number Two,Number Three} % renders fine \end{document}