\여러 열 숨기기

\여러 열 숨기기

주 문서에 동일한 표를 여러 번 배치했습니다. 이를 위해 테이블의 내용은 model-values.tex. 마다 \input로 열을 숨겨 표시할 테이블 부분을 변경합니다 \newcolumntype. 나는 거대한 Gnumeric 테이블(TeX 내보내기)로 작업하고 형식적인 이유로만 분할하고 싶지 않기 때문에 이 솔루션을 사용합니다.

\multicolumn테이블에 s가 있으면 숨기기가 더 이상 작동하지 않습니다 . 열이 숨겨져 있어도 해당 텍스트는 계속 표시됩니다. H 유형 열에 대해 이미 다른 솔루션을 시도했지만(설명의 TeX SE 링크 참조) 문제가 지속됩니다.

한 가지 해결 방법은 파일에서 헤더를 꺼내 테이블의 여러 항목에 넣는 것입니다. 그러나 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

다중 열은 일반적으로 두 개 이상의 열에 걸쳐 있으므로 "the" 열 유형을 상속해야 한다는 생각은 별로 의미가 없습니다. 그리고 한 열의 경우 명시적으로 기존 열 유형을 덮어쓰도록 되어 있습니다.

일부 더미 열과 스위치를 사용하여 여러 열을 숨길 수 있습니다. 그러나 열과 줄 사이의 공백을 올바르게 얻으려면 약간의 조정이 필요합니다. 그리고 처음에는 부울 값을 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}

관련 정보