我有一个表,我将用几个变量条目重复生成该表(表中的行数和列数是固定的):
愛爾蘭人 | 韋斯特 | 韋斯特 |
---|---|---|
愛爾蘭 | 蒂亞特 | 类型 |
कर्म | 蒂亞特 | 类型 |
संबंध | 专辑 | 特罗夫 |
愛爾蘭人 | 剧院 | 特別 |
家 | 剧院 | 特別 |
韓國 | 剧院 | 特別 |
梵文部分保持不变,西里尔文部分会有所不同。为此,我创建了一个\gencasetable
接受参数的函数。我收到错误
Latex3 error: Too many arguments in argument specification
。我还尝试使用分号分隔列表\SplitArgument
,但似乎也无法正常工作。在后一种情况下,我无法访问“拆分”参数。
以下是一个例子:
\documentclass{book}
\usepackage{ltablex}
\usepackage{booktabs} % for \toprule \midrule \bottomrule in tables
\usepackage[backend=biber,
style=numeric]{biblatex}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english,russian,hindi]{babel} % last language in the entry is treated as the main language
\usepackage{imakeidx}
\usepackage[log-declarations=true]{xparse}
\usepackage{xcolor} % Compiler recommended to load package
\usepackage{fontspec} % Compiler recommended to load package
\usepackage{csquotes} % Compiler recommended to load package
\babelfont[hindi]{rm}{Aparajita}
\babelfont[russian]{rm}{Arial}
\NewDocumentCommand{\gencasetable}{m m m m m m m m m m m m m m}
{
% First parameter = table caption
% Second parameter = table label
% Third parameter = List of ; separated table entries
\begin{tabularx} {\linewidth} { c | X | X | }
\caption{#13}\label{#14}\tabularnewline
\toprule
\midrule
\textbf{कारक} & \textbf{एकवचन} & \textbf{बहुवचन} \tabularnewline
\midrule
\endfirsthead
\midrule
\textbf{कारक} & \textbf{एकवचन} & \textbf{बहुवचन} \tabularnewline
\midrule
\endhead
\multicolumn{3}{r}{\footnotesize{अगले पृष्ट पर जारी}}
\endfoot
\bottomrule
\multicolumn{3}{r}{\footnotesize{इति तालिका~\ref{#14} }} \tabularnewline
\endlastfoot
कर्ता & \foreignlanguage{russian}{#1} & \foreignlanguage{russian}{#2}
\tabularnewline
\hline
कर्म & \foreignlanguage{russian}{#3} & \foreignlanguage{russian}{#4}
\tabularnewline
\hline
संबंध & \foreignlanguage{russian}{#5} & \foreignlanguage{russian}{#6}
\tabularnewline
\hline
संप्रदान & \foreignlanguage{russian}{#7} & \foreignlanguage{russian}{#8}
\tabularnewline
\hline
अधिकरण & \foreignlanguage{russian}{#9} & \foreignlanguage{russian}{#10}
\tabularnewline
\hline
करण & \foreignlanguage{russian}{#11} & \foreignlanguage{russian}{#12}
\end{tabularx}
}
% Used for tabularx package to put some gap between text and row heights
\renewcommand{\arraystretch}{1.5}
\title{हिन्दी भाषियों के लिए रूसी अध्यन}
\begin{document}
\gencasetable{театр}{театры}{театр}{театры}{театра}{театров}{театре}{театрых}{театру}{театрам}{театром}{театрами}{\ru{р}-कारांत संज्ञा}{tab:noun-endings-g}
\end{document}
答案1
我没有字体来呈现结果,但我建议使用类似的东西listofitems
将输入解析为单个参数。在这里,我将列表分隔符设置为空格,但您可以更改它,因为否则在输入列表中放置空格会很困难。
您说天城体部分保持不变,这意味着行数是固定的(我在这里使用的就是这个)。如果不是这样,您必须以某种方式更好地解释它应该如何工作。
ps\ru
未定义,因此我设置了\newcommand\ru[1]{#1}
。
pps 我对表格的其他部分(页眉和页脚)没有经验,无法为这些部分提供修复/解释。
\documentclass{book}
\usepackage{ltablex}
\usepackage{booktabs} % for \toprule \midrule \bottomrule in tables
\usepackage[backend=biber,
style=numeric]{biblatex}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english,russian,hindi]{babel} % last language in the entry is treated as the main language
\usepackage{imakeidx}
\usepackage[log-declarations=true]{xparse}
\usepackage{xcolor} % Compiler recommended to load package
\usepackage{fontspec} % Compiler recommended to load package
\usepackage{csquotes} % Compiler recommended to load package
\usepackage{listofitems}
\babelfont[hindi]{rm}{Aparajita}
\babelfont[russian]{rm}{Arial}
\newcommand\ru[1]{#1}
\NewDocumentCommand{\gencasetable}{m}
{
% First parameter = table caption
% Second parameter = table label
% Third parameter = List of ; separated table entries
\setsepchar{ }%
\readlist\z{#1}%
\begin{tabularx} {\linewidth} { c | X | X | }
\caption{\z[13]}\label{\z[14]}\tabularnewline
\toprule
\midrule
\textbf{कारक} & \textbf{एकवचन} & \textbf{बहुवचन} \tabularnewline
\midrule
\endfirsthead
\midrule
\textbf{कारक} & \textbf{एकवचन} & \textbf{बहुवचन} \tabularnewline
\midrule
\endhead
\multicolumn{3}{r}{\footnotesize{अगले पृष्ट पर जारी}}
\endfoot
\bottomrule
\multicolumn{3}{r}{\footnotesize{इति तालिका~\ref{\z[14]} }} \tabularnewline
\endlastfoot
कर्ता & \foreignlanguage{russian}{\z[1]} & \foreignlanguage{russian}{\z[2]}
\tabularnewline
\hline
कर्म & \foreignlanguage{russian}{\z[3]} & \foreignlanguage{russian}{\z[4]}
\tabularnewline
\hline
संबंध & \foreignlanguage{russian}{\z[5]} & \foreignlanguage{russian}{\z[6]}
\tabularnewline
\hline
संप्रदान & \foreignlanguage{russian}{\z[7]} & \foreignlanguage{russian}{\z[8]}
\tabularnewline
\hline
अधिकरण & \foreignlanguage{russian}{\z[9]} & \foreignlanguage{russian}{\z[10]}
\tabularnewline
\hline
करण & \foreignlanguage{russian}{\z[11]} & \foreignlanguage{russian}{\z[12]}
\end{tabularx}
}
% Used for tabularx package to put some gap between text and row heights
\renewcommand{\arraystretch}{1.5}
\title{हिन्दी भाषियों के लिए रूसी अध्यन}
\begin{document}
\gencasetable{%
театр театры театр театры
театра театров театре театрых
театру театрам театром театрами
\ru{р}-कारांत संज्ञा tab:noun-endings-g}
\end{document}
对于有同样编译问题的其他人来说...如果我用拉丁文本替代天城文,并将英语设为默认语言,则可以毫无问题地进行编译:
\documentclass{book}
\usepackage{ltablex}
\usepackage{booktabs} % for \toprule \midrule \bottomrule in tables
\usepackage[backend=biber,
style=numeric]{biblatex}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[russian,english]{babel} % last language in the entry is treated as the main language
\usepackage{imakeidx}
\usepackage[log-declarations=true]{xparse}
\usepackage{xcolor} % Compiler recommended to load package
\usepackage{fontspec} % Compiler recommended to load package
\usepackage{csquotes} % Compiler recommended to load package
\usepackage{listofitems}
\babelfont[russian]{rm}{Arial}
\newcommand\ru[1]{#1}
\NewDocumentCommand{\gencasetable}{m}
{
% First parameter = table caption
% Second parameter = table label
% Third parameter = List of ; separated table entries
\setsepchar{ }%
\readlist\z{#1}%
\begin{tabularx} {\linewidth} { c | X | X | }
\caption{\z[13]}\label{\z[14]}\tabularnewline
\toprule
\midrule
\textbf{A} & \textbf{B} & \textbf{C} \tabularnewline
\midrule
\endfirsthead
\midrule
\textbf{D} & \textbf{E} & \textbf{F} \tabularnewline
\midrule
\endhead
\multicolumn{3}{r}{\footnotesize{G}}
\endfoot
\bottomrule
\multicolumn{3}{r}{\footnotesize{H~\ref{\z[14]} }} \tabularnewline
\endlastfoot
I & \foreignlanguage{russian}{\z[1]} & \foreignlanguage{russian}{\z[2]}
\tabularnewline
\hline
J & \foreignlanguage{russian}{\z[3]} & \foreignlanguage{russian}{\z[4]}
\tabularnewline
\hline
K & \foreignlanguage{russian}{\z[5]} & \foreignlanguage{russian}{\z[6]}
\tabularnewline
\hline
L & \foreignlanguage{russian}{\z[7]} & \foreignlanguage{russian}{\z[8]}
\tabularnewline
\hline
M & \foreignlanguage{russian}{\z[9]} & \foreignlanguage{russian}{\z[10]}
\tabularnewline
\hline
N & \foreignlanguage{russian}{\z[11]} & \foreignlanguage{russian}{\z[12]}
\end{tabularx}
}
% Used for tabularx package to put some gap between text and row heights
\renewcommand{\arraystretch}{1.5}
\title{Title}
\begin{document}
\gencasetable{%
театр театры театр театры
театра театров театре театрых
театру театрам театром театрами
\ru{J}-J tab:noun-endings-g}
\end{document}
答案2
TeX 宏中的参数数量限制为 9 个,请参阅TeX 简介, 例如。
您的案例可以按照以下方式解决:
\def\gencasetable #1#2#3#4#5#6#7#8{%
\def\gencasetableA{%
कर्ता & \foreignlanguage{russian}{#1} & \foreignlanguage{russian}{#2}
\tabularnewline
\hline
कर्म & \foreignlanguage{russian}{#3} & \foreignlanguage{russian}{#4}
\tabularnewline
\hline
संबंध & \foreignlanguage{russian}{#5} & \foreignlanguage{russian}{#6}
\tabularnewline
\hline
संप्रदान & \foreignlanguage{russian}{#7} & \foreignlanguage{russian}{#8}
\tabularnewline
\hline
}\gencasetableB
}
\def\gencasetableB #1#2#3#4#5#6{%
\begin{tabularx} {\linewidth} { c | X | X | }
\caption{#5}\label{#6}\tabularnewline
\toprule
\midrule
\textbf{कारक} & \textbf{एकवचन} & \textbf{बहुवचन} \tabularnewline
\midrule
\endfirsthead
\midrule
\textbf{कारक} & \textbf{एकवचन} & \textbf{बहुवचन} \tabularnewline
\midrule
\endhead
\multicolumn{3}{r}{\footnotesize{अगले पृष्ट पर जारी}}
\endfoot
\bottomrule
\multicolumn{3}{r}{\footnotesize{इति तालिका~\ref{#14} }} \tabularnewline
\endlastfoot
\gencasetableA
अधिकरण & \foreignlanguage{russian}{#1} & \foreignlanguage{russian}{#2}
\tabularnewline
\hline
करण & \foreignlanguage{russian}{#3} & \foreignlanguage{russian}{#4}
\end{tabularx}
}
答案3
TeX 仅支持 9 个参数#1
,虽然#9
可以使用一些内部辅助命令来抓取 14 个括号组的列表,但具有那么多参数的命令不是一个非常友好的用户界面。
如果将它们组合在一起,则需要的参数更少,这里我最终得到了 8 个,但这仍然比您真正想要的要多。
\documentclass{article}
\newcommand\zz[8]{%
\begin{table}[htp]
\centering
\caption{#1\label{#2}}
\begin{tabular}{ccc}
AAA&BBB&CCC\\
\hline
Z1\\
Z2\\
Z3\\
Z4\\
Z5\\
Z6
\end{tabular}
\end{table}}
\begin{document}
\zz{A caption}{tab:zzz}
{111 & 222}
{333 & 444}
{555 & 666}
{777 & 888}
{999 & AAA}
{BBB & CCC}
\end{document}
答案4
您可以用分号分隔列表。不需要ltablex
,因为此类表格不应跨页拆分。
\documentclass{book}
\usepackage[english,russian,hindi]{babel} % last language in the entry is treated as the main language
\usepackage{fontspec} % Compiler recommended to load package
\usepackage{booktabs} % for \toprule \midrule \bottomrule in tables
\usepackage{capt-of,array}
\babelfont[hindi]{rm}{ITF Devanagari}
\babelfont[russian]{rm}{Old Standard}
\newcommand{\ru}[1]{\foreignlanguage{russian}{#1}} % ???
\ExplSyntaxOn
\NewDocumentCommand{\gencasetable}{m m m}
{
% #1 = List of ; separated table entries
% #2 = table caption
% #3 = table label
\group_begin:
\setlength{\tabcolsep}{0pt}
\vinay_gencasetable:nnn { #1 } { #2 } { #3 }
\group_end:
}
\seq_new:N \l__vinay_gencasetable_items_seq
\cs_new_protected:Nn \__vinay_gencasetable_case:n
{
\foreignlanguage{russian}{ \seq_item:Nn \l__vinay_gencasetable_items_seq { #1 } }
}
\cs_new_protected:Nn \vinay_gencasetable:nnn
{
\seq_set_split:Nnn \l__vinay_gencasetable_items_seq { ; } { #1 }
\begin{tabular}
{
w{c}{\dim_eval:n { \linewidth/3 }}
w{c}{\dim_eval:n { \linewidth/3 }}
w{c}{\dim_eval:n { \linewidth/3 }}
}
\multicolumn{3}{c}{\parbox{\linewidth}{\captionof{table}{#2}\label{#3}}}
\tabularnewline
\midrule[\heavyrulewidth]
\textbf{कारक} & \textbf{एकवचन} & \textbf{बहुवचन}\tabularnewline
\midrule
कर्ता & \__vinay_gencasetable_case:n {1} & \__vinay_gencasetable_case:n {2}
\tabularnewline
कर्म & \__vinay_gencasetable_case:n {3} & \__vinay_gencasetable_case:n {4}
\tabularnewline
संबं ध & \__vinay_gencasetable_case:n {5} & \__vinay_gencasetable_case:n {6}
\tabularnewline
संप्रदान & \__vinay_gencasetable_case:n {7} & \__vinay_gencasetable_case:n {8}
\tabularnewline
अधिकरण & \__vinay_gencasetable_case:n {9} & \__vinay_gencasetable_case:n {10}
\tabularnewline
करण & \__vinay_gencasetable_case:n {11} & \__vinay_gencasetable_case:n {12}
\tabularnewline
\midrule[\heavyrulewidth]
\multicolumn{3}{r}{\footnotesize इति तालिका~\ref{#3}}
\end{tabular}
}
\ExplSyntaxOff
% Used for tabularx package to put some gap between text and row heights
\renewcommand{\arraystretch}{1.5}
\title{हिन्दी भाषियों के लिए रूसी अध्यन}
\begin{document}
\gencasetable{
театр;театры;
театр;театры;
театра;театров;
театре;театрых;
театру;театрам;
театром;театрами
}{\ru{р}-कारांत संज्ञा}{tab:noun-endings-g}
\end{document}