I want to save some typing when I use a comon style for my tables.
But because \caption and \label have to be used inside the float, I want to pass the values for these macros via arguments into my envrionment.
I want to keep these inside the end code of my environment, to easily keep the caption at the bottom of the table.
Here is the MWE to my problem:
\documentclass[
fontsize=12pt,
a4paper
]{scrreprt}
\newenvironment{bordertab}[2]
{
\begin{table}
\centering
\begin{tabular}{| l c r |}
\hline
}
{
\hline
\end{tabular}
\caption{#1}
\label{tab:b:#2}
\end{table}
}
\begin{document}
\begin{bordertab}{A table with a border}{ex1}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\end{bordertab}
\end{document}
and the errors which LaTeX throws at me when using it:
! Illegal parameter number in definition of \reserved@a.
<to be read again>
1
l.28 ^^I\end{bordertab}
You meant to type ## instead of #, right?
Or maybe a } was forgotten somewhere earlier, and things
are all screwed up? I'm going to assume that you meant ##.
! You can't use `macro parameter character #' in restricted horizontal mode.
<argument> \ignorespaces ##
1
l.28 ^^I\end{bordertab}
Sorry, but I'm not programmed to handle this case;
I'll just pretend that you didn't ask for it.
If you're in the wrong mode, you might be able to
return to the right one by typing `I}' or `I$' or `I\par'.
! You can't use `macro parameter character #' in restricted horizontal mode.
<argument> \ignorespaces ##
1
l.28 ^^I\end{bordertab}
Sorry, but I'm not programmed to handle this case;
I'll just pretend that you didn't ask for it.
If you're in the wrong mode, you might be able to
return to the right one by typing `I}' or `I$' or `I\par'.
! Illegal parameter number in definition of \reserved@a.
<to be read again>
2
l.28 ^^I\end{bordertab}
You meant to type ## instead of #, right?
Or maybe a } was forgotten somewhere earlier, and things
are all screwed up? I'm going to assume that you meant ##.
\labelin the second argument (in order to keep this functionality, if you care about it, of course...). – Guilherme Zanotelli Dec 14 '16 at 14:38