6

\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}}

しかし、環境の最後でパラメーターを使用できないため、それは機能しません。どうすればこの問題を解決できますか?

4

2 に答える 2

4

キャプションとラベルのパラメーターを保存して、後で使用する必要があります。(また、\label は \caption の後に表示する必要があります。)

このようなものが動作するはずです:

\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}%
}

次のような環境を使用します。

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

このコードはテストしていません。

于 2009-09-07T18:34:59.410 に答える
-3

新しい環境の代わりにカットアンドペーストを使用しますか?私は\newenvを確信しています。そのように使用することを意図したものではありません。これのポイントは何ですか?毎回すべてを入力しないようにするには?

于 2009-09-07T18:12:26.210 に答える