Latex 命令反射

发布于 2024-08-12 15:41:03 字数 360 浏览 3 评论 0原文

我有以下用例:表格有一个节、小节或小节标题,例如:

    \section*{Table name}
    \begin{tabular*} ...
    \end{tabular*}

因为表格可以出现在节、小节等中。我想我可以将表页眉和页脚定义为宏,并另外传递表格标题的类型(节,小节,子小节,段落...)所以这需要我有类似的东西:

    \#1*{Table name}
    \begin{tabular*} ...
    \end{tabular*}

其中#1是传递的宏参数。有没有机会实现某事。像这样?

非常感谢,
奥瓦内斯

I have the following use case: A table have a section, subsection or subsubsection heading like:

    \section*{Table name}
    \begin{tabular*} ...
    \end{tabular*}

Because the table can appear in section, subsection etc. I thought I could define the table header and footer as macros and additionally pass the type of table heading (section, subsection, subsubsection, paragraph ...) So this requires me to have something like:

    \#1*{Table name}
    \begin{tabular*} ...
    \end{tabular*}

where #1 is the macro parameter passed. Is there any chance to achieve smth. like this?

Many thanks,
Ovanes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗地喜欢 2024-08-19 15:41:03

当然,你已经差不多明白了。 (尽管您使用节标题而不是表格标题有什么原因吗?)

\newenvironment{tablesection}[2][\section]{
  #1*{#2}
  \begin{tabular*}
}{
  \end{tabular*}
}

并将其用作

\begin{tablesection}[\subsection]{Table Name}{cc}
a & bb \\
aa & b \\
\end{tablesection}

如果省略方括号中的可选参数,则默认使用 \section

请记住,(La)TeX 使用宏扩展,因此您在输入中传递的任何标记流都可以用作宏定义中的替换文本。 (对“特殊字符”有一定的限制,如 % 等。)

Sure, you've almost got it. (Although is there a reason you're using section headings rather than table captions?)

\newenvironment{tablesection}[2][\section]{
  #1*{#2}
  \begin{tabular*}
}{
  \end{tabular*}
}

and use it as

\begin{tablesection}[\subsection]{Table Name}{cc}
a & bb \\
aa & b \\
\end{tablesection}

If you omit the optional argument in square brackets, \section is used by default.

Remember (La)TeX works with macro expansion, so any stream of tokens you pass it in the input can be used as the replacement text in the macro definition. (With certain restrictions with "special characters" like % and so on.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文