1

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}
CarLaTeX
  • 62,716

2 Answers2

2

put

 \def\zzzzz{{\footnotesize #3\par}}

in your begin-code, and then use

\zzzzz

in the end code where you want it to appear. (Note \footnotesize doesn't have an argument so I moved the brace.)

David Carlisle
  • 757,742
1

You could solve your problem using the environ package and the following:

\NewEnviron{tabella}[3]{%before
    \begin{table}[t]
    \centering 
    \begin{threeparttable}[b]
    \caption{\label{tab:#1}#2}
    \small
    \BODY
    \begin{tablenotes}[para,flushleft]    
       {\footnotesize #3}
    \end{tablenotes}     
    \end{threeparttable}
    \end{table}
}
TeXnician
  • 33,589