我希望自动填充一个表格,该表格确实用序列填充水平表,并用自动填充的下表的第二列填充。
\documentclass[11pt, fleqn]{examdesign}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\SectionFont{\large\sffamily}
\usepackage[font=scriptsize,hypcap=false]{caption}
\Fullpages
\ContinuousNumbering
\ShortKey
\class{Needed for Examdesign}%%necessary for examdesign class
\begin{document}
\begin{shortanswer}
\begin{block}
\parbox{\linewidth}{
\begin{tabular}{c c c c}
5 & 7&9&11 \\
\end{tabular}\vspace{5mm}\\
\renewcommand{\arraystretch}{2}
\begin{tabular}{|c|c|c|}
\hline
\shortstack{Term\\ Number}& Term &\shortstack{Ordered\\ Pair}\\
\hline
1 & 5&\normalsize(1,5)\\
\hline
2 & 7&\normalsize(\enspace\enspace,\enspace\enspace)\\
\hline
3 &9 &\normalsize(\enspace\enspace,\enspace\enspace)\\
\hline
4 &11 &\normalsize(\enspace\enspace,\enspace\enspace)\\
\hline
\end{tabular}
}
\begin{question}hi
\begin{answer}
hello
\end{answer}
\end{question}
\end{block}
\end{shortanswer}
\end{document}
我希望宏能执行类似以下操作:\Mysequence{3,5,7,9,11},然后输出两个表格以水平方向包含 3,5,7,9,11,并在下面的表格中自动显示第二列中的 3,5,7,9,11。请帮忙,谢谢。
我还想确保每次调用序列时都重置术语编号。
答案1
处理&
自动生成的表中的问题是有点棘手的,但存在多种方法来处理这个问题。这个答案采用了etoolbox
基于这里.\docsvlist
使用了三次,
- 生成 s 序列来
c
指定第一个表中的列, - 填充第一列中的列,以及
- 生成第二个表的行。
我不太确定我是否理解\parbox
这里的用途但我保留了它。
\documentclass[11pt, fleqn]{examdesign}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{etoolbox}
\newcounter{irow}
\SectionFont{\large\sffamily}
\usepackage[font=scriptsize,hypcap=false]{caption}
\Fullpages
\ContinuousNumbering
\ShortKey
\class{Needed for Examdesign}%%necessary for examdesign class
\newcommand{\Mysequence}[1]{% based on https://tex.stackexchange.com/a/15520
\edef\mytabcols{}%
\renewcommand*\do[1]{\appto\mytabcols{c}}%
\docsvlist{#1}%
\edef\myflag{0}%
\edef\mytabrow{}%
\renewcommand*\do[1]{\ifnum\myflag=0
\typeout{0}
\appto\mytabrow{##1}%
\edef\myflag{1}
\else
\appto\mytabrow{& ##1}%
\fi
}%
\docsvlist{#1}%
\def\mytabrows{}%
\setcounter{irow}{0}%
\renewcommand*\do[1]{%
\appto\mytabrows{\stepcounter{irow}\number\value{irow}& ##1 &
(\number\value{irow},##1) \\ \hline}}%
\docsvlist{#1}%
\begin{tabular}{\mytabcols}
\mytabrow \\[5mm]
\end{tabular}\par
\renewcommand{\arraystretch}{2}
\begin{tabular}{|c|c|c|}
\hline
\shortstack{Term\\ Number}& Term &\shortstack{Ordered\\ Pair}\\
\hline
\mytabrows
\end{tabular}}
\begin{document}
\begin{shortanswer}
\begin{block}
\parbox{\linewidth}{\Mysequence{3,5,7,9,11}}
\begin{question}hi
\begin{answer}
hello
\end{answer}
\end{question}
\end{block}
\end{shortanswer}
\end{document}