如何使用 LaTeX 创建自定义表格环境,并在表格末尾添加标题?
我有一个用 \newenvironment 定义的自定义表环境。我在这个环境中有一个标题,但我想在最后有它。
我的环境看起来(有点简化)如下:
\newenvironment{mytable}[2]{\begin{table}[hbtp]\caption{#1}\label{#1}\begin{center}\begin{tabular}{#2}}{\end{tabular}\end{center}\end{table}}
我想将标题放在末尾,如下所示:
\newenvironment{mytable}[2]{\begin{table}[hbtp]\label{#1}\begin{center}\begin{tabular}{#2}}{\caption{#1}\end{tabular}\end{center}\end{table}}
但这不起作用,因为我无法在环境末尾使用参数。我该如何解决这个问题?
I have a custom table-environment defined with \newenvironment. I have a caption in this environment, but I want to have it at the end.
My environment looks (a little simplified) like this:
\newenvironment{mytable}[2]{\begin{table}[hbtp]\caption{#1}\label{#1}\begin{center}\begin{tabular}{#2}}{\end{tabular}\end{center}\end{table}}
I want to put the caption at the end, like this:
\newenvironment{mytable}[2]{\begin{table}[hbtp]\label{#1}\begin{center}\begin{tabular}{#2}}{\caption{#1}\end{tabular}\end{center}\end{table}}
But that doesn't work, because I cannot use the parameters in the end of the environment. How can I solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要存储标题和标签参数并在以后使用它们。 (此外, \label 应该出现在 \caption 之后。)
类似这样的东西应该有效:
使用这样的环境:
我还没有测试过这段代码。
You'll want to store the caption and label parameters and use them later. (Also, the \label should appear after the \caption.)
Something like this should work:
Use the environment like this:
I haven't tested this code.
使用剪切和粘贴而不是新环境?我非常确定\newenv。并不意味着以这种方式使用。这有什么意义呢?不每次都把它全部输入吗?
use cut and paste instead of a new environment? i am fairy certain the \newenv. is not meant to be used in that manner. what is the point of this? to not type it all out every time?