Pregunta

Tengo una tabla con el medio personalizado definido con \ newenvironment. Tengo un título en este entorno, pero yo quiero tener al final.

Mi entorno se ve un poco (simplificado) como este:

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

Quiero poner el título al final, como esto:

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

Pero eso no funciona, porque no puedo utilizar los parámetros en el extremo del medio ambiente. ¿Cómo puedo solucionar este problema?

¿Fue útil?

Solución

querrá para almacenar los parámetros de subtítulos y etiquetas y usarlos más tarde. (También, la \ etiqueta debe aparecer después de la \ caption.)

Algo como esto debería funcionar:

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

El uso del entorno como este:

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

No he probado este código.

Otros consejos

El uso de cortar y pegar en lugar de un nuevo entorno? estoy seguro de que el hada \ nuevoentorno. no está destinado a ser usado de esta manera. ¿Cual es el punto de esto? a lo escriba todo lo alto todo el tiempo?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top