How to create a self-defined table-environment with an inscription at the end of the table using LaTeX?

I have a custom environment table defined in \ newenvironment. I have a signature in this environment, but I want it to be at the end.

My environment looks (slightly simplified) as follows:

\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 a signature at the end, for example:

\newenvironment{mytable}[2]{\begin{table}[hbtp]\label{#1}\begin{center}\begin{tabular}{#2}}{\caption{#1}\end{tabular}\end{center}\end{table}}

But this does not work, because I can not use the parameters at the end of the environment. How can I solve this problem?

+5
source share
2 answers

You need to save the title and label parameters and use them later. (Also, \ label should appear after \ caption.)

Something like this should work:

\newcommand{\templabel}{}% stores the label
\newcommand{\tempcaption}{}% stores the caption

\newenvironment{mytable}[3]{%
  \gdef\templabel{#1}% store the label so we can use it later
  \gdef\tempcaption{#2}% store the caption so we can use it later
  \begin{table}[hbtp]% 
    \begin{center}%
      \begin{tabular}{#3}%
}{%
        \caption{\tempcaption}% use the stored caption
        \label{\templabel}% use the stored label (*after* the caption)
      \end{tabular}%
    \end{center}%
  \end{table}%
}

Use the following environment:

\begin{mytable}{tab:example}{This is the caption for my example table.}{cc}
  Row 1 & First \\
  Row 2 & Second \\
  Row 3 & Third \\
\end{mytable}

I have not tested this code.

+4

? , \newenv. . ​​ ? ?

-2

All Articles