
まず、私はかなり具体的なことをしたいので、かなり長いプリアンブルを持つ LyX を使用していますが、プリアンブル内のコードはほとんどすべて、ネットから切り取って貼り付け、少し修正したものです。私は TeX の達人ではありませんが、TeX の達人が必要です!
フロート テーブル環境では、ほぼ常にゼブラ テーブルを使用しています。また、フロート フィギュア環境もいくつかありますが、これらは実際にはテーブルではないため、ゼブラ効果をオフにしたいと考えています。説明するのは難しく、例を添付することもできないようです。
私が欲しいのは、Float: Figure 環境にあるときに Zebra テーブルをオフにする条件 (ERT で問題ありませんが、プリアンブルに収めることができればさらに良いです) です。
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}