



\newcommand{\chooseFigPos}[1]{%
 %\def\CFP@@Pos{#1}
 \def\CFP@Pos{}
 \def\CFP@Tail{{figure}[\CFP@Pos]}
 \ifx\CFP@Pos\empty
  \begin{figure}[htbp]%
 \else\expandafter\begin\CFP@Tail\fi
}

% Env for figure
\newenvironment{Figure}[3]{%
  \def\F@Pos{\chooseFigPos{#1}}
  \def\F@Cap{#2}
  \def\F@Lab{#3}
  \F@Pos
}{%
  \caption{\F@Cap}
  \label{\F@Lab}
  \end{figure}
}

\newenvironment{CenterFigure}[3]{%
  \def\F@Pos{\chooseFigPos{#1}}
  \def\F@Cap{#2}
  \def\F@Lab{#3}
  \F@Pos
  \begin{center}
}{%
  \end{center}
  \caption{\F@Cap}
  \label{\F@Lab}
  \end{figure}
}

% Env for tabular figure
\newenvironment{TabularFigure}[4]{%
  \begin{Figure}{#1}{#2}{#3}
  \begin{tabular}{#4}
  \hline
%  \\
}{%
  \\
  \hline
  \end{tabular}
  \end{Figure}
}

% Env for centered tabular figure
\newenvironment{TabularCenterFigure}[4]{%
  \begin{CenterFigure}{#1}{#2}{#3}
  \begin{tabular}{#4}
  \hline
%  \\
}{%
  \\
  \hline
  \end{tabular}
  \end{CenterFigure}
}

% Plain figure
\newenvironment{PlainFigure}[3]{%
  \begin{TabularFigure}{#1}{#2}{#3}{p{.98\linewidth}}
}{%
  \end{TabularFigure}
}

% Plain figure
\newenvironment{PlainCenterFigure}[3]{%
  \begin{PlainFigure}{#1}{#2}{#3}
  \begin{center}
}{%
  \end{center}
  \end{PlainFigure}
}

