i try to write a short macro to align some (3) words one below the other in one cell of a table, like here: tabular inside a newcommand
For a reason I do not understand it does not work.
Here is my code:
\documentclass[11pt]{article}
\usepackage[table]{xcolor}
\usepackage{cite}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{censor}
\usepackage[a4paper, left=3cm, right=2cm, top=2.5cm, bottom=2.5cm]{geometry}
\usepackage{setspace}
\usepackage{graphicx}
\usepackage[hidelinks]{hyperref}
\usepackage{pdfpages}
%my command to create the tabular
\newcommand{\cellincell}[3]{
\begin{tabular}{l}
#1 \\
#2 \\
#3 \\
\end{tabular}
}
\begin{document}
%only writes 'test1,test2,test3' plain in one line
\cellincell{test1,test2,test3}
%works as intended
%\begin{tabular}{l}
%test1 \\
%test2 \\
%test3 \\
%\end{tabular}
\begin{table}
\caption{this is how it should look like}
\begin{tabular}{|l|l|l|l|}
\hline
Trimround & \multicolumn{1}{c|}{I} & \multicolumn{1}{c|}{II} & \multicolumn{1}{c|}{III} \\ \hline
number & \begin{tabular}{l}
test1 \\
test2 \\
test3 \\
\end{tabular} & text & \\ \hline
\end{tabular}
\end{table}
%throws: ! Extra alignment tab has been changed to \cr. (l. 56)
\begin{table}
\begin{tabular}{|l|l|l|l|}
\hline
Trimround & \multicolumn{1}{c|}{I} & \multicolumn{1}{c|}{II} & \multicolumn{1}{c|}{III} \\ \hline
%number & \cellincell{test1,test2,test3} & text & \\ \hline
\end{tabular}
\end{table}
\end{document}
Thanks a lot
Best Answer
Here, I use a
\Centerstack
to construct\cellincell
, and also manage the comma parsing.