我知道我以前見過這個排版問題,但我找不到解決方案。乳膠可能非常違反直覺。我想做的就是建立一個 \panel{} 標頭類型宏,該宏在稍微修改的表中運作。 \panel 應增加與前一個表格的間距,並減少與下一個表格的間距。
我已經剝離了一個例子來說明這個問題。如何定義一個 \panel 巨集來完成預期的任務?
\documentclass{article}
\usepackage{color}
\usepackage{booktabs}
\newsavebox{\selvesteboxtwo}
\newenvironment{colboxfigtbl}
{
\begin{lrbox}{\selvesteboxtwo}%
\begin{minipage}{\dimexpr\columnwidth-2\fboxsep-4em\relax}}
{
\end{minipage}\end{lrbox}%
\begin{center}%
\fcolorbox{blue}{yellow}{\usebox{\selvesteboxtwo}}%%real life do more
\end{center}
}
\newenvironment{newtable}[1][]{%
\begin{table}%
\begin{center}%
\begin{colboxfigtbl}
}{%
\end{colboxfigtbl}%
\end{center}%
\end{table}
}
\newcommand{\panel}[2]{%
\par\bigskip%
\begin{center} \textbf{Panel #1:} #2 \end{center}%
\par\vspace*{-1.5\baselineskip}%
}
\begin{document}
\begin{newtable}
\panel{A}{This is a bad panel}
\begin{center}\begin{tabular}{l r} \toprule A & B \\ \bottomrule \end{tabular} \end{center}
\panel{B}{This is a better panel}
\begin{center}\begin{tabular}{l r} \toprule A & B \\ \bottomrule \end{tabular} \end{center}
\panel{C}{This is a better panel}
\begin{center}\begin{tabular}{l r} \toprule A & B \\ \bottomrule \end{tabular} \end{center}
\end{newtable}
\end{document}
答案1
通常,將環境嵌套在一起可能很棘手,因為環境往往會在其內容的上方和下方添加空間。最重要的是,某些環境試圖變得聰明並減去嵌套環境插入的額外空間。在像您這樣的情況下,答案很簡單:在\newtable
已呼叫table
環境的環境中,將巢狀\begin{center}...\end{center}
環境替換為\centering...
,這是一種無需環境即可實現相同效果的巨集形式。
\documentclass{article}
\usepackage{color}
\usepackage{booktabs}
\newsavebox{\selvesteboxtwo}
\newenvironment{colboxfigtbl}
{
\begin{lrbox}{\selvesteboxtwo}%
\begin{minipage}{\dimexpr\columnwidth-2\fboxsep-4em\relax}}
{
\end{minipage}\end{lrbox}%
\begin{center}%
\fcolorbox{blue}{yellow}{\usebox{\selvesteboxtwo}}%%real life do more
\end{center}
}
\newenvironment{newtable}[1][]{%
\begin{table}%
\centering%\begin{center}%
\begin{colboxfigtbl}
}{%
\end{colboxfigtbl}%
% \end{center}%
\end{table}
}
\newcommand{\panel}[2]{%
\par\bigskip%
\begin{center} \textbf{Panel #1:} #2 \end{center}%
\par\vspace*{-1.5\baselineskip}%
}
\begin{document}
\begin{newtable}
\panel{A}{This is a bad panel}
\begin{center}\begin{tabular}{l r} \toprule A & B \\ \bottomrule \end{tabular} \end{center}
\panel{B}{This is a better panel}
\begin{center}\begin{tabular}{l r} \toprule A & B \\ \bottomrule \end{tabular} \end{center}
\panel{C}{This is a better panel}
\begin{center}\begin{tabular}{l r} \toprule A & B \\ \bottomrule \end{tabular} \end{center}
\end{newtable}
\end{document}