I have the following use case: A table have a section, subsection or subsubsection heading like:
\section*{Table name}
\begin{tabular*} ...
\end{tabular*}
Because the table can appear in section, subsection etc. I thought I could define the table header and footer as macros and additionally pass the type of table heading (section, subsection, subsubsection, paragraph …) So this requires me to have something like:
\#1*{Table name}
\begin{tabular*} ...
\end{tabular*}
where #1 is the macro parameter passed. Is there any chance to achieve smth. like this?
Many thanks,
Ovanes
Sure, you’ve almost got it. (Although is there a reason you’re using section headings rather than table captions?)
\newenvironment{tablesection}[2][\section]{ #1*{#2} \begin{tabular*} }{ \end{tabular*} }and use it as
\begin{tablesection}[\subsection]{Table Name}{cc} a & bb \\ aa & b \\ \end{tablesection}If you omit the optional argument in square brackets,
\sectionis used by default.Remember (La)TeX works with macro expansion, so any stream of tokens you pass it in the input can be used as the replacement text in the macro definition. (With certain restrictions with “special characters” like
%and so on.)