I am trying to define a new table environment with optional caption. However, if I don't pass it the caption, I am still getting the "Table 1.1:" below the table. What am I missing here? Thanks. Examples below.
If I call it like this, it works as supposed.
\begin{mytable}[This is the caption]
% table content goes here
\end{mytable}
But if I call it like this, I get the "Table 1.1:" but nothing after. In the case with no caption provided, I obviously would like for the "Table 1.1:" not to appear.
\begin{mytable}
% table content goes here
\end{mytable}
newenvironment definition:
\def\mycaption{\relax}
\newenvironment{mytable}[1][]
{
\if\relax\detokenize{#1}\relax
\gdef\mycaption{\relax}
\else
\gdef\mycaption{#1}
\fi
\begin{table}[ht]
\centering
\begin{tabular}{lccc}
& \textbf{\vocalsn} & \textbf{\nonvocalsn} & \textit{Totals} \\
\hline
}
{
\hline
\end{tabular}
\caption{\mycaption}
\fi
\end{table}
}