
首先,我使用帶有相當長的序言的 LyX,因為我想要相當具體的內容,但序言中的幾乎所有代碼都是從網絡剪切粘貼的,並進行了一些修改。我不是 TeX 大師,但我需要一位!
我幾乎總是在浮動表環境中使用 Zebra 表。我還有一些浮動圖形環境,我希望關閉它們的斑馬效果,因為它不是真正的桌子。很難解釋,而且看起來我無法附上例子。
我想要的是一個條件(ERT 很好,但如果我可以將其放入序言中,那就更好了),當 Zebra 表處於 Float: Figure 環境中時,它會關閉它。
這是我用於 Zebra 表(和其他表格式)的內容...
%
% Zebra Tables w/footnotes
%
\let\mytoprule\toprule
\renewcommand{\toprule}{\mytoprule[2pt]}
\let\mybottomrule\bottomrule
\renewcommand{\bottomrule}{\mybottomrule[2pt]}
\let\mymidrule\midrule
\renewcommand{\midrule}{\mymidrule[1pt]}
\let\tabulary\tabular
\let\endtabulary\endtabular
\renewenvironment{tabular}{\rowcolors{2}{white}{shadecolor}\tabulary} {\endtabulary}
\usepackage{footnote}
\makesavenoteenv{tabular}
那麼,當 \tabular 處於 Float: Figure 環境中時,如何關閉所有這些功能?
答案1
如果我很明白你在問什麼,你可以用這個etoolbox
包來做到這一點:
\documentclass[a4paper, 11pf]{article}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[table, x11names]{xcolor}
\usepackage{booktabs, caption}
\colorlet{shadecolor}{LightSteelBlue1}
\let\mytoprule\toprule
\renewcommand{\toprule}{\mytoprule[2pt]}
\let\mybottomrule\bottomrule
\renewcommand{\bottomrule}{\mybottomrule[2pt]}
\let\mymidrule\midrule
\renewcommand{\midrule}{\mymidrule[1pt]}
\let\tabulary\tabular
\let\endtabulary\endtabular
\renewenvironment{tabular}{\ifbool{intableenv}{\rowcolors{2}{white}{shadecolor}}{}\tabulary} {\endtabulary}
\usepackage{etoolbox}
\newbool{intableenv}
\AtBeginEnvironment{table}{\booltrue{intableenv}}%{}{}
\AtEndEnvironment{table}{\boolfalse{intableenv}}{}{}
\begin{document}
\begin{table}[!h]
\centering
\caption{A Zebra Table}
\begin{tabular}{llccc}
\toprule
\multicolumn{2}{c} {}& \textbf{Head 1} & \textbf{Head 2} & \textbf{Head 3} \\
\midrule
A & & & & \\
B & & & & \\
C & & & & \\
D & & & & \\
E & & & & \\
F & & & & \\
G & & & & \\
\bottomrule
\end{tabular}%
\end{table}
\begin{figure}[!h]
\centering
\begin{tabular}{llccc}
\toprule
\multicolumn{2}{c}{} & \textbf{Head 1} & \textbf{Head 2} & \textbf{Head 3} \\
\midrule
A & & & & \\
B & & & & \\
C & & & & \\
D & & & & \\
E & & & & \\
F & & & & \\
G & & & & \\
\bottomrule
\end{tabular}%
\caption{Same table}
\end{figure}
\end{document}