我正在编写一个类文件。我正在为我的自定义定义一个变量,\maketitle
如下所示:
\newcommand*{\comment}[1]{\def\commentname{#1}}
\comment{}
我希望能够编写如下评论列表:
\comment{
Comment1: this is a comment.
Comment2: this is also a comment.
etc.
}
然后我想\maketitle
形成一个表格,每个评论都单独占一行。表格最好有动态的行数,这样添加的评论就会增加表格的大小。
这可能吗?!
答案1
我将使用不同的输入语法,将每个注释作为单独的命令而不是拆分段落:
\documentclass{article}
\newcounter{comment}
\def\comments{}
\makeatletter
\newcommand\comment[1]{%
\stepcounter{comment}%
\def\tmp##1{\g@addto@macro\comments{Comment ##1 & #1\\}}%
\expandafter\tmp\expandafter{\the\c@comment}}
\makeatother
\begin{document}
\comment{first thing}
\comment {second thing}
\comment {a very very liong third thing}
\begin{tabular}{|l|c|}
\comments
\end{tabular}
\end{document}
或者,如果您想要明确的评论标签而不是计数器,这会更容易一些
\documentclass{article}
\newcounter{comment}
\def\comments{}
\makeatletter
\newcommand\comment[2]{%
\g@addto@macro\comments{Comment #1 & #2\\}}
\makeatother
\begin{document}
\comment{com 1}{first thing}
\comment{com B}{second thing}
\comment{comment three}{a very very liong third thing}
\begin{tabular}{|l|c|}
\comments
\end{tabular}
\end{document}