![如何创建 \newenvironment{name}[num]{before}{after} 并在 {after} 中带有参数](https://linux22.com/image/349238/%E5%A6%82%E4%BD%95%E5%88%9B%E5%BB%BA%20%5Cnewenvironment%7Bname%7D%5Bnum%5D%7Bbefore%7D%7Bafter%7D%20%E5%B9%B6%E5%9C%A8%20%7Bafter%7D%20%E4%B8%AD%E5%B8%A6%E6%9C%89%E5%8F%82%E6%95%B0%20.png)
我的表格全部格式如下:
\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}
我想创建一个新环境(这是我第一次这样做!)以便仅输入其中指示的部分<...>
。
我尝试了这个,但是没有用:
\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}
答案1
environ
您可以使用该包和以下内容解决您的问题:
\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}
}
答案2
放
\def\zzzzz{{\footnotesize #3\par}}
在你的开始代码中,然后使用
\zzzzz
在您希望它出现的最后代码中。(注意,\footnotesize
没有参数,因此我移动了括号。)