这是我的fsmpic.cls:
\NeedsTeXFormat{LaTeX2e}
\LoadClass[version=last]{scrlttr2}
\RequirePackage[utf8]{inputenc}
\RequirePackage[T1]{fontenc}
\RequirePackage[ngerman]{babel}
\usepackage[scaled]{helvet}
\renewcommand{\familydefault}{\sfdefault}
\KOMAoption{parskip}{full-}
\RequirePackage[a4paper,]{geometry}
\RequirePackage{tabularx}
\RequirePackage{ltablex}
\RequirePackage{booktabs}
\keepXColumns
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{\L}{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}X}
\setlength{\heavyrulewidth}{0.6pt}
\setlength{\lightrulewidth}{0.3pt}
\setlength{\tabcolsep}{1mm}
\renewcommand{\arraystretch}{1.2}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MyEnviron
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{environ}
\NewEnviron{MyEnviron}[3]{%
\newcounter{fsmpic@MyCounter}%
\begin{tabularx}{\linewidth}{%
L{15mm}%
\L%
L{25mm}%
L{15mm}%
R{25mm}%
R{25mm}%
}%
\textbf{A} & \textbf{B} & \textbf{Menge} & \textbf{USt.} & \textbf{Einzelpreis} & \textbf{Summe} \\%
\toprule\endhead%
\BODY%
\midrule%
\multicolumn{5}{\L}{Some Text} & #1 \\%
\MyCommand{#2}%
\bottomrule%
\multicolumn{5}{\L}{\textbf{More Text}} & \textbf{#3}%
\end{tabularx}%
}
\ExplSyntaxOn
\NewDocumentCommand{\MyCommand}{ >{ \SplitList {,} } m }
{
\ProcessList {#1} {\fsmpic_process_argument:n}
}
\cs_new_protected:Nn \fsmpic_process_argument:n
{
\fsmpic_column:nn #1
}
\cs_new_protected:Nn \fsmpic_column:nn
{
\multicolumn{5}{\L}{Text #1 Another Text} & #2 \\
\penalty0
}
\ExplSyntaxOff
\newcommand{\MySecondCommand}[5]{\stepcounter{fsmpic@MyCounter}\thefsmpic@MyCounter & #1 & #2 & #3 & #4 & #5 \\}
这是我的 tex.tex:
\documentclass[tex]{fsmpic}
\begin{document}
\begin{letter}{}
\opening{Opening,}
\begin{MyEnviron}{Number A}{{B}{C},{D}{E}}{F}
\MySecondCommand{Some Text}{G}{H}{I}{J}
\end{MyEnviron}
\end{letter}
\end{document}
SplitList 运行良好,但是带有多行的 tabularx 布局\fsmpic_column
完全被破坏了。
我究竟做错了什么?
编辑:压缩文件以便于测试
\documentclass{article}
\usepackage[a4paper,]{geometry}
\usepackage{tabularx}
\usepackage{ltablex}
\usepackage{booktabs}
\keepXColumns
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{\L}{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}X}
\setlength{\heavyrulewidth}{0.6pt}
\setlength{\lightrulewidth}{0.3pt}
\setlength{\tabcolsep}{1mm}
\renewcommand{\arraystretch}{1.2}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MyEnviron
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{environ}
\NewEnviron{MyEnviron}[3]{
\newcounter{fsmpic@MyCounter}
\begin{tabularx}{\linewidth}{
L{15mm}
X
L{25mm}
L{15mm}
R{25mm}
R{25mm}
}
\textbf{A} & \textbf{B} & \textbf{C} & \textbf{D} & \textbf{E} & \textbf{F} \\
\toprule\endhead
\BODY
\midrule
\multicolumn{5}{\L}{Some Text} & #1 \\
\MyCommand{#2}
\bottomrule
\multicolumn{5}{\L}{\textbf{More Text}} & \textbf{#3}
\end{tabularx}
}
\ExplSyntaxOn
\NewDocumentCommand{\MyCommand}{ >{ \SplitList {,} } m }
{
\ProcessList {#1} {\fsmpic_process_argument:n}
}
\cs_new_protected:Nn \fsmpic_process_argument:n
{
\fsmpic_column:nn #1
}
\cs_new_protected:Nn \fsmpic_column:nn
{
\multicolumn{5}{\L}{Text #1 Another Text} & #2 \\
\penalty0
}
\ExplSyntaxOff
\newcommand{\MySecondCommand}[5]{\stepcounter{fsmpic@MyCounter}\thefsmpic@MyCounter & #1 & #2 & #3 & #4 & #5 \\}
\begin{document}
\begin{MyEnviron}{Number A}{{B}{C},{D}{E}}{F}
\MySecondCommand{Some Text}{G}{H}{I}{J}
\end{MyEnviron}
\end{document}
答案1
您不应将其用作\L
列类型,因为这是一个现有命令。我改用M
。
问题是\multicolumn
必须首先(扩展后)出现在表格单元格中,但您的\MyCommand
不可扩展。
\ExplSyntaxOn
\NewExpandableDocumentCommand{\MyCommand}{ m }
{
\clist_map_function:nN { #1 } \fsmpic_process_argument:n
}
\cs_new:Nn \fsmpic_process_argument:n
{
\fsmpic_column:nn #1
}
\cs_new:Nn \fsmpic_column:nn
{
\multicolumn{5}{M}{Text #1 Another Text} & #2 \\
}
\ExplSyntaxOff
顺便说一句,environ
已经被认为是过时的了。
\newcounter{fsmpic@MyCounter}
\NewDocumentEnvironment{MyEnviron}{mmm+b}{%
\setcounter{fsmpic@MyCounter}{0}%
\begin{tabularx}{\linewidth}{
L{15mm}
X
L{25mm}
L{15mm}
R{25mm}
R{25mm}
}
\textbf{A} & \textbf{B} & \textbf{C} & \textbf{D} & \textbf{E} & \textbf{F} \\
\toprule\endhead
#4
\midrule
\multicolumn{5}{M}{Some Text} & #1 \\
\MyCommand{#2}
\bottomrule
\multicolumn{5}{M}{\textbf{More Text}} & \textbf{#3}
\end{tabularx}
}{}
当然,\newcounter
必须超出环境的定义。