My tables are all formatted like this:
\begin{table}[t]
\centering
\begin{threeparttable}
\caption{\label{tab:<my label>}<my table title>}
\small%
<the actual table>
\begin{tablenotes}[para,flushleft]
\footnotesize{<the table notes>}
\end{tablenotes}
\end{threeparttable}
\end{table}
I'd like to create a new environment (it's the first time I do that!) in order to type only the parts indicated within <...>.
I tried this, but it doesn't work:
\documentclass[11pt,openright]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=3cm,bmargin=3.5cm,lmargin=4cm,rmargin=3cm,marginparwidth=70pt}
\usepackage{comment}
\usepackage{prettyref}
\usepackage{setspace}
\usepackage{fancyhdr}
\usepackage[normalem]{ulem}
\usepackage{setspace}
\usepackage{bigstrut}
\usepackage{array}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{dcolumn}
\usepackage{multirow}
\renewcommand{\multirowsetup}{\centering}
\usepackage[para,flushleft]{threeparttable}
\usepackage{makecell}
\usepackage[margin=10pt,font=small,labelfont=bf,labelsep=period,format=hang,indention=0cm]{caption}
\captionsetup[table]{position=above, belowskip=4pt}
\newenvironment{tabella}[3]{%before
\begin{table}[t]
\centering
\begin{threeparttable}[b]
\caption{\label{tab:#1}#2}
\small
}
{%after
\begin{tablenotes}[para,flushleft]
\footnotesize{#3}
\end{tablenotes}
\end{threeparttable}
\end{table}
}
\begin{document}
% Example of working table without new environment
\begin{table}[t]
\centering
\begin{threeparttable}
\caption{\label{tab:mytab1}Example without new environment}
\small%
\begin{tabular}{@{}ccc@{}}
\toprule
\addlinespace
Ducks & Lions & Penguins\\
\addlinespace
\midrule
1& 2& 3\\
Quack & Roar & ?\tnote{a}\\
\bottomrule
\end{tabular}
\begin{tablenotes}[para,flushleft]
\footnotesize{\item[a] What is the call of the penguins?\\\emph{Source}: blah, blah, blah.}
\end{tablenotes}
\end{threeparttable}
\end{table}
% Example of not working table with new environment
\begin{tabella}{mytab2}{Example with new environment}
{\item[a] What is the call of the penguins?\\\emph{Source}: blah, blah, blah.}
\begin{tabular}{@{}lll@{}}
\toprule
\addlinespace
Ducks & Lions & Penguins\\
\addlinespace
\midrule
1& 2& 3\\
Quack & Roar & ?\tnote{a}\\
\bottomrule
\end{tabular}
\end{tabella}
\end{document}
environpackage? – TeXnician Feb 10 '17 at 08:38\newenvironmentdoes not provide arguments in the\end-code. Usexparseand\NewDocumentEnvironment. Alternatively store the argument in an temporary macro and use the macro instead of the argument. – Schweinebacke Feb 10 '17 at 08:42