
私はメイン文書に同じ表を複数回配置しています。そのために、表の内容は というファイルに配置されていますmodel-values.tex
。 ごとに\input
、 で列を非表示にして、表示する表の部分を変更します\newcolumntype
。私は巨大な Gnumeric 表 (TeX エクスポート) を扱っており、書式設定上の理由だけで表を分割したくないので、このソリューションを使用しています。
テーブルに sがある場合、非表示は機能しなくなります\multicolumn
。列が非表示になっているかどうかに関係なく、これらのテキストは引き続き表示されます。H タイプの列に対してすでにさまざまな解決策を試しましたが (コメントの TeX SE リンクを参照)、問題は解決しません。
解決策の 1 つは、ファイルからヘッダーを取り出し、それをテーブルの複数の箇所に配置することです。ただし、列を追加または削除する場合はmodel-values.tex
、テーブルのヘッダー全体を変更する必要があります。外部ファイルにヘッダーが含まれている場合は、変更する行が 1 つ (列定義) だけであるのに対し、変更する行が 2 つ多くなります。
それは価値があるのでしょうか、それともヘッド全体を変更するソリューションに固執するべきでしょうか? 問題は の列タイプにあると思います。テーブルc
の列タイプ\multicolumn
などを「継承」する必要があります。
\documentclass{scrartcl}
\usepackage{booktabs}
\usepackage{tabularx}
% Hidden column type - different solutions on http://tex.stackexchange.com/questions/16604/easiest-way-to-delete-a-column
\newcolumntype{H}{>{\setbox0=\hbox\bgroup}c<{\egroup}@{}}
\begin{filecontents}{model-values.tex}
% Header
Model
& Param a
& \multicolumn{3}{c}{Param set A}
& \multicolumn{2}{c}{Param set B}
\\\cmidrule{3-5}\cmidrule{6-7}
&
& Param A1
& Param A2
& Param A3
& Param B1
& Param B2
\\\midrule
% Data
1 & 5 & 6 & 9 & 11 & 2 & 4\\
\end{filecontents}
\begin{document}
\section{Comparison of param set A}
Here, param set A of all models are compared, refer the table.
\begin{table}[t]
\begin{tabular}{
l % Model
c % Param a
c % Param set A: A1
c % Param set A: A2
c % Param set A: A3
H % Param set B: B1
H % Param set B: B2
}
\toprule
\input{model-values.tex}
\bottomrule
\end{tabular}
\end{table}
\clearpage
\section{Comparison of param set B}
Here, param set B of all models are compared, refer the table.
\begin{table}[t]
\begin{tabular}{
l % Model
c % Param a
H % Param set A: A1
H % Param set A: A2
H % Param set A: A3
c % Param set B: B1
c % Param set B: B2
}
\toprule
\input{model-values.tex}
\bottomrule
\end{tabular}
\end{table}
\end{document}
答え1
マルチカラムは一般に複数の列にまたがるため、列タイプを継承するという考えはあまり意味がありません。また、1 つの列の場合、既存の列タイプを明示的に上書きすることを意味します。
ダミーの列とスイッチを使用すると、複数列を非表示にすることができます。ただし、列と行の間のスペースを正しく取得するには、少し調整が必要です。また、最初にブール値を false にリセットするように注意する必要があります。
\documentclass{scrartcl}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{filecontents}
% Hidden column type - different solutions on http://tex.stackexchange.com/questions/16604/easiest-way-to-delete-a-column
\newcolumntype{H}{@{}>{\setbox0=\hbox\bgroup}c<{\egroup}@{}}
\newif\ifhidden
\begin{filecontents}{model-values.tex}
% Header
Model
& Param a
& \ifhidden\multicolumn{3}{@{}c@{}}{}\else\multicolumn{3}{c}{Param set A}\fi
&
& \ifhidden\multicolumn{2}{@{}c@{}}{}\else\multicolumn{2}{c}{Param set B}\fi
\\\cmidrule{3-5}\cmidrule{7-8}
&
& Param A1
& Param A2
& Param A3
&
& Param B1
& Param B2
\\\midrule
% Data
1 & 5 & 6 & 9 & 11 && 2 & 4\\
1 & 5 & 6 & 9 & 11 && 2 & 4\\
\end{filecontents}
\begin{document}
\section{Comparison of param set A}
Here, param set A of all models are compared, refer the table.
\begin{table}[t]
\begin{tabular}{
l<{\global\hiddenfalse} % Model
c % Param a
c % Param set A: A1
c % Param set A: A2
c % Param set A: A3
@{}l<{\global\hiddentrue}%dummy column to hold the switch
H % Param set B: B1
H % Param set B: B2
}
\toprule
\input{model-values.tex}
\bottomrule
\end{tabular}
\end{table}
\section{Comparison of param set B}
Here, param set B of all models are compared, refer the table.
\begin{table}[t]
\begin{tabular}{
l <{\global\hiddenfalse} % Model% Model
c <{\global\hiddentrue}% Param a
H % Param set A: A1
H % Param set A: A2
H % Param set A: A3
@{}l <{\global\hiddenfalse}
c % Param set B: B1
c % Param set B: B2
}
\toprule
\input{model-values.tex}
\bottomrule
\end{tabular}
\end{table}
\end{document}