다음과 같이 쉼표로 구분된 데이터를 기반으로 테이블을 생성하고 싶습니다.
\documentclass{article}
\usepackage{pgffor}
\usepackage{multirow}
\usepackage{float}
\newcommand{\cases}{a , b}
\newcommand{\repetir}{
\foreach \case in {\cases}{
\case & & & & & & & & & & & & & & & \\\hline
}
}
\begin{document}
\begin{table}[H]
\centering
\scriptsize
\begin{tabular}{ | p{4cm} | p{3cm} |l| l|l|l| l | l | l | l | l| l | l | l | l | p{3cm} | }
\hline
\multirow{3}{*}{Case name} & \multirow{3}{*}{Description} & \multicolumn{14}{c|}{Further Details} \\\cline{3-16}
& & \multicolumn{3}{c|}{O} & \multicolumn{3}{c|}{A} & \multicolumn{2}{c|}{F} & \multicolumn{2}{c|}{B} & & \multirow{2}{*}{G} & \multirow{2}{*}{C} & \multirow{2}{*}{Other} \\ \cline{3-13}
& 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 \\ \hline
\repetir
\end{tabular}
\end{table}
\end{document}
그러나 항상 오류가 발생합니다.
Extra } or forgotten \endgroup \repetir.
어떻게 해야 하나요?
답변1
\foreach
표 셀에서 시작하여 다른 셀에서 끝날 수는 없습니다 .
\documentclass{article}
\usepackage[a4paper,landscape]{geometry}
\usepackage{multirow}
\usepackage{xparse}
% a command for doing the repetitive things:
% 1. open center, 2. choose the font size,
% 3. start the tabular, 4. print the header
% Next the command processes the argument and
% ends the job
\NewDocumentCommand{\chungeltable}{m}
{%
\begin{center}\scriptsize
\begin{tabular}{ | p{4cm} | p{3cm} | *{13}{l|} p{3cm} | }
\hline
\multirow{3}{*}{Case name} &
\multirow{3}{*}{Description} &
\multicolumn{14}{c|}{Further Details} \\
\cline{3-16}
& & \multicolumn{3}{c|}{O} & \multicolumn{3}{c|}{A} & \multicolumn{2}{c|}{F} &
\multicolumn{3}{c|}{B} & \multirow{2}{*}{G} & \multirow{2}{*}{C} & \multirow{2}{*}{Other} \\
\cline{3-13}
& & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & & & \\ \hline
\chungeltablebody{#1}
\end{tabular}
\end{center}
}
\ExplSyntaxOn
\NewDocumentCommand{\chungeltablebody}{m}
{
% clear the variable that will contain the table body
\tl_clear:N \l_tmpa_tl
% for each item in the comma separated list
\clist_map_inline:nn { #1 }
{
% add the item followed by the necessary number of &'s
% to the variable containing the table body
\tl_put_right:Nn \l_tmpa_tl { ##1 & & & & & & & & & & & & & & & \\\hline }
}
% deliver the table body
\tl_use:N \l_tmpa_tl
}
\ExplSyntaxOff
\begin{document}
\chungeltable{a,b}
\end{document}
핵심은 \clist_map_inline:nn
; 첫 번째 인수의 각 항목은 #1
두 번째 인수의 코드로 전달됩니다.
우리는 정의의 본문에 있기 때문에 #1
가 되어야 합니다 ##1
. 왜냐하면 는 #1
우리가 정의하는 매크로에 대한 실제 인수이기 때문입니다.