여러 열과 여러 행이 있는 longtabu

여러 열과 여러 행이 있는 longtabu

@Zarko가 제안한 코드를 사용했습니다. 지금까지는 스크린샷에 표시된 것처럼 페이지 프레임에서 떨어지는 것처럼 보이는 다중 행을 제외하고는 작동합니다. 누구든지 아이디어가 있나요?

\documentclass[12pt]{article}
\usepackage[onehalfspacing]{setspace}
\usepackage[american]{babel}
\usepackage{booktabs, multirow, longtable, tabu}
\usepackage{siunitx}

\usepackage{color}
\definecolor{gray}{rgb}{0.8,0.8,0.8}
\usepackage{colortbl}    


\begin{document}

\begin{longtabu} to \textwidth { X[1, l] X[1, l] 
                           *{6}{S[table-format=2.3]}
                            }
\toprule
\toprule
& & \multicolumn{3}{c}{\textbf{def1}} & \multicolumn{3}{c}{\textbf{def2}} \\
\cmidrule(lr){3-5}\cmidrule(lr){6-8}
& & {contrast} & {t} & {p} & {contrast} & {t} & {p} \\ 
\endfirsthead
\toprule
& & \multicolumn{3}{c}{\textbf{def1}} & \multicolumn{3}{c}{\textbf{def2}} \\
& & contrast & t & p & contrast & t & p \\
\toprule
\endhead
\bottomrule
\multicolumn{8}{r}{continued on the next page} \\
\endfoot
\bottomrule
\bottomrule
\endlastfoot

\toprule
\multicolumn{8}{c}{\textbf{group1}} \\
\toprule
\multirow{6}{*}{\textbf{design1}}  
& pos1 & 15.05 & 1.06 & 0.145 & -3.41 & -0.28 & 0.610 \\
& pos2 & 9.20 & 0.65 & 0.258 & -4.02 & -0.32 & 0.627 \\
& pos3 & 32.92 & 2.30 & \cellcolor{gray}0.011 & 4.87 & 0.40 & 0.344 \\
& pos4 & 6.46 & 0.69 & 0.247 & 3.94 & 0.45 & 0.327 \\
& pos5 & 10.99 & 0.87 & 0.191 & 0.41 & 0.03 & 0.486 \\
& pos6 & 36.70 & 2.20 & \cellcolor{gray}0.014 & 30.20 & 1.94 & \cellcolor{gray}0.026 \\
\midrule
\multirow{6}{*}{\textbf{design2}}
& pos1 & 6.51 & 0.87 & 0.192 & -2.79 & -0.41 & 0.661 \\
& pos2 & 1.91 & 0.29 & 0.385 & -3.21 & -0.54 & 0.706 \\
& pos3 & 16.49 & 2.52 & \cellcolor{gray}0.006 & 4.21 & 0.73 & 0.233 \\
& pos4 & 4.42 & 0.96 & 0.168 & 1.15 & 0.28 & 0.391 \\
& pos5 & 0.13 & 0.02 & 0.491 & -0.26 & -0.05 & 0.521 \\
& pos6 & 11.73 & 1.63 & \cellcolor{gray}0.052 & 12.18 & 1.88 & \cellcolor{gray}0.031 \\
\midrule
\multirow{6}{*}{\textbf{design3}}
& pos1 & 17.02 & 1.18 & 0.119 & -5.75 & -0.46 & 0.678 \\
& pos2 & 11.08 & 0.77 & 0.220 & -3.85 & -0.30 & 0.618 \\
& pos3 & 35.82 & 2.41 & \cellcolor{gray}0.008 & 6.00 & 0.48 & 0.316 \\
& pos4 & 9.59 & 0.96 & 0.170 & 1.78 & 0.19 & 0.423 \\
& pos5 & 9.25 & 0.70 & 0.243 & 0.86 & 0.07 & 0.472 \\
& pos6 & 34.91 & 1.99 & \cellcolor{gray}0.024 & 32.28 & 2.04 & \cellcolor{gray}0.021 \\
\toprule
\multicolumn{8}{c}{\textbf{group2}} \\
\toprule
\multirow{6}{*}{\textbf{design1}}
& pos1 & 16.98 & 1.07 & 0.142 & -10.16 & -0.70 & 0.759 \\
& pos2 & 18.47 & 1.10 & 0.136 & 2.77 & 0.18 & 0.429 \\
& pos3 & 15.28 & 1.23 & 0.110 & 16.18 & 1.41 & 0.079 \\
& pos4 & 21.38 & 1.92 & \cellcolor{gray}0.027 & -0.18 & -0.02 & 0.507 \\
& pos5 & 30.56 & 2.54 & \cellcolor{gray}0.006 & 16.49 & 1.50 & 0.067 \\
& pos6 & 29.32 & 3.40 & \cellcolor{gray}0.000 & -7.31 & -0.98 & 0.836 \\
\midrule
\multirow{6}{*}{\textbf{design2}}
& pos1 & 5.45 & 0.71 & 0.239 & -3.97 & -0.56 & 0.712 \\
& pos2 & 9.89 & 1.48 & 0.070 & -0.84 & -0.14 & 0.554 \\
& pos3 & 7.32 & 1.38 & 0.084 & 4.53 & 0.93 & 0.176 \\
& pos4 & 10.15 & 2.04 & \cellcolor{gray}0.021 & -0.86 & -0.19 & 0.575 \\
& pos5 & 11.09 & 2.20 & \cellcolor{gray}0.014 & 3.13 & 0.67 & 0.250 \\
& pos6 & 9.31 & 1.88 & \cellcolor{gray}0.030 & -3.42 & -0.75 & 0.774 \\
\midrule
\multirow{6}{*}{\textbf{design3}}
& pos1 & 16.54 & 1.06 & 0.145 & -7.81 & -0.55 & 0.709 \\
& pos2 & 11.86 & 0.72 & 0.236 & -6.58 & -0.43 & 0.667 \\
& pos3 & 15.75 & 1.29 & 0.099 & 14.89 & 1.32 & 0.093 \\
& pos4 & 25.87 & 2.36 & \cellcolor{gray}0.009 & -1.19 & -0.12 & 0.548 \\
& pos5 & 30.73 & 2.59 & \cellcolor{gray}0.005 & 14.17 & 1.31 & 0.096 \\
& pos6 & 31.61 & 3.66 & \cellcolor{gray}0.000 & -6.28 & -0.85 & 0.802 \\
\end{longtabu}

\end{document}

여기에 이미지 설명을 입력하세요

답변1

패키지를 사용하여 siunitx:

여기에 이미지 설명을 입력하세요

\documentclass[12pt]{article}
\usepackage[american]{babel}
\usepackage{siunitx} % <-- added
\usepackage{booktabs, multirow, longtable, tabu}
\usepackage[onehalfspacing]{setspace}


%\usepackage{showframe}
\begin{document}

\begin{longtabu} to \textwidth { X[1.5, l] X[1, l] 
                               *{6}{S[table-format=2.3]} % <-- changed
                                }
\toprule
    & & \multicolumn{3}{c}{\textbf{def1}}   & \multicolumn{3}{c}{\textbf{def2}} \\
    \cmidrule(lr){3-5}\cmidrule(lr){6-8}
    & & {contrast} & {t} & {p}              & {contrast} & {t} & {p}            \\ 
\midrule
\endfirsthead
\toprule
    & & \multicolumn{3}{c}{\textbf{def1}}   & \multicolumn{3}{c}{\textbf{def2}} \\
    \cmidrule(lr){3-5}\cmidrule(lr){6-8}
    & & contrast & t & p                    & contrast & t & p \\
\midrule
\endhead
    \bottomrule
\multicolumn{8}{r}{continued on the next page} \\
\endfoot
\bottomrule
\endlastfoot
% end of tabu preamble
\multicolumn{8}{c}{\textbf{group 1}} \\
\midrule
\multirow{6}{*}{\textbf{design1}}  
    & pos1  & 15.05 & 1.06 & 0.145 & -3.41 & -0.28 & 0.610 \\
    & pos2  & 9.20  & 0.65 & 0.258 & -4.02 & -0.32 & 0.627 \\
    & pos3  & 32.92 & 2.30 & 0.011 &  4.87 &  0.40 & 0.344 \\
    & pos4  & 6.46  & 0.69 & 0.247 &  3.94 &  0.45 & 0.327 \\
    & pos5  & 10.99 & 0.87 & 0.191 &  0.41 &  0.03 & 0.486 \\
    & pos6  & 36.70 & 2.20 & 0.014 & 30.20 &  1.94 & 0.026 \\
%\midrule
\end{longtabu}

\end{document}

longtabu또한 "premble" 도 변경했습니다 . 즉, 중복된 규칙을 제거했습니다. 표시된 결과는 MWE 컴파일을 두 번째 실행한 후에 얻은 것입니다.

편집하다: 내 MWE를 사용하면 이제 전체 테이블이 완성되어 원하고 예상되는 결과를 얻을 수 있습니다.

여기에 이미지 설명을 입력하세요

아래 제안된 MWE와 문제의 코드 사이의 차이점을 관찰하십시오! 내 MWE에서는 코드를 정리하는 데 상당한 노력을 기울였습니다. 여기에서는 \multicolumns머리글과 바닥글에 대한 불필요하고 재설계된 정의가 모두 제거되었으며, 변경 사항은 잘못 사용된 규칙 등을 포함합니다.

\documentclass[12pt]{article}
\usepackage[american]{babel}
\usepackage{siunitx}
\usepackage{booktabs, multirow, longtable, tabu}
\usepackage[onehalfspacing]{setspace}

%---------------------------------------------------------------%
\usepackage{showframe}% to show page layout
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}

\begin{longtabu} to \textwidth { X[1.5, l] X[1, l]
                               *{6}{S[table-format=2.3]}
                                }
\toprule
    & & \multicolumn{3}{c}{\textbf{def1}}   & \multicolumn{3}{c}{\textbf{def2}} \\
    \cmidrule(lr){3-5}\cmidrule(lr){6-8}
    & & {contrast} & {t} & {p}              & {contrast} & {t} & {p}            \\
\midrule
\endfirsthead
\toprule
    & & \multicolumn{3}{c}{\textbf{def1}}   & \multicolumn{3}{c}{\textbf{def2}} \\
    \cmidrule(lr){3-5}\cmidrule(lr){6-8}
    & & contrast & t & p                    & contrast & t & p \\
\midrule
\endhead
    \bottomrule
\multicolumn{8}{r}{continued on the next page} \\
\endfoot
\bottomrule
\endlastfoot
% end of tabu preamble
\multicolumn{8}{c}{\textbf{group 1}} \\
\midrule
\multirow{6}{*}{\textbf{design1}}
    & pos1  & 15.05 & 1.06 & 0.145 & -3.41 & -0.28 & 0.610 \\
    & pos2  & 9.20  & 0.65 & 0.258 & -4.02 & -0.32 & 0.627 \\
    & pos3  & 32.92 & 2.30 & 0.011 &  4.87 &  0.40 & 0.344 \\
    & pos4  & 6.46  & 0.69 & 0.247 &  3.94 &  0.45 & 0.327 \\
    & pos5  & 10.99 & 0.87 & 0.191 &  0.41 &  0.03 & 0.486 \\
    & pos6  & 36.70 & 2.20 & 0.014 & 30.20 &  1.94 & 0.026 \\
\midrule
\multirow{6}{*}{\textbf{design2}}  
    & pos1  & 6.51  & 0.87 & 0.192 & -2.79 & -0.41 & 0.661 \\
    & pos2  & 1.91  & 0.29 & 0.385 & -3.21 & -0.54 & 0.706 \\
    & pos3  & 16.49 & 2.52 & 0.006 & 4.21  &  0.73 & 0.233 \\
    & pos4  & 4.42  & 0.96 & 0.168 & 1.15  &  0.28 & 0.391 \\
    & pos5  & 0.13  & 0.02 & 0.491 & -0.26 & -0.05 & 0.521 \\
    & pos6  & 11.73 & 1.63 & 0.052 & 12.18 &  1.88 & 0.031 \\
\midrule
\multirow{6}{*}{\textbf{design3}}  
    & pos1  & 17.02 & 1.18 & 0.119 & -5.75 & -0.46 & 0.678 \\
    & pos2  & 11.08 & 0.77 & 0.220 & -3.85 & -0.30 & 0.618 \\
    & pos3  & 35.82 & 2.41 & 0.008 &  6.00 &  0.48 & 0.316 \\
    & pos4  & 9.59  & 0.96 & 0.170 &  1.78 &  0.19 & 0.423 \\
    & pos5  & 9.25  & 0.70 & 0.243 &  0.86 &  0.07 & 0.472 \\
    & pos6  & 34.91 & 1.99 & 0.024 & 32.28 &  2.04 & 0.021 \\
\midrule
\multicolumn{8}{c}{\textbf{group2}} \\
\midrule
\multirow{6}{*}{\textbf{design1}}  
    & pos1  & 16.98 & 1.07 & 0.142 & -10.16 & -0.70 & 0.759 \\
    & pos2  & 18.47 & 1.10 & 0.136 &  2.77  &  0.18 & 0.429 \\
    & pos3  & 15.28 & 1.23 & 0.110 & 16.18  &  1.41 & 0.079 \\
    & pos4  & 21.38 & 1.92 & 0.027 & -0.18  & -0.02 & 0.507 \\
    & pos5  & 30.56 & 2.54 & 0.006 & 16.49  &  1.50 & 0.067 \\
    & pos6  & 29.32 & 3.40 & 0.000 & -7.31  & -0.98 & 0.836 \\
\midrule
\multirow{6}{*}{\textbf{design2}}  
    & pos1  & 5.45  & 0.71 & 0.239 & -3.97 & -0.56 & 0.712 \\
    & pos2  & 9.89  & 1.48 & 0.070 & -0.84 & -0.14 & 0.554 \\
    & pos3  & 7.32  & 1.38 & 0.084 &  4.53 &  0.93 & 0.176 \\
    & pos4  & 10.15 & 2.04 & 0.021 & -0.86 & -0.19 & 0.575 \\
    & pos5  & 11.09 & 2.20 & 0.014 &  3.13 &  0.67 & 0.250 \\
    & pos6  & 9.31  & 1.88 & 0.030 & -3.42 & -0.75 & 0.774 \\
\midrule
\multirow{6}{*}{\textbf{design3}}  
    & pos1  & 16.54 & 1.06 & 0.145 & -7.81 & -0.55 & 0.709 \\
    & pos2  & 11.86 & 0.72 & 0.236 & -6.58 & -0.43 & 0.667 \\
    & pos3  & 15.75 & 1.29 & 0.099 & 14.89 &  1.32 & 0.093 \\
    & pos4  & 25.87 & 2.36 & 0.009 & -1.19 & -0.12 & 0.548 \\
    & pos5  & 30.73 & 2.59 & 0.005 & 14.17 &  1.31 & 0.096 \\
    &¸pos6  & 31.61 & 3.66 & 0.000 & -6.28 & -0.85 & 0.802 \\
\end{longtabu}

\end{document}

메모: longtable(또한 longtabu) 시작 새 행의 페이지 사이에서 테이블을 나누려고 합니다. multirow셀을 사용하는 경우 longtable하나의 행으로 간주하여 페이지 간에 분리될 수 없습니다(패키지 작성자의 "흑마술"이 없으면 참조).질문: longtable을 사용할 때 여러 행 셀을 여러 페이지로 분할하는 것이 가능합니까?).

문제의 MWE에 대한 테스트에서는 보고된 문제가 재현되지 않았으므로 귀하의 컴퓨터에 "마법"이 있다는 결론만 내릴 수 있습니다. 절박한 시도는 LeTeX 설치를 업그레이드하거나 다른 컴퓨터나 다른 이름으로 MWE를 테스트하는 것입니다.

답변2

예를 들어 \lipsum[3]테이블 앞에 문제가 재현 가능합니다.

를 사용하면 표 형식 줄 다음에 페이지 나누기를 방지할 수 있습니다 \\*. 다음 예제에서는 페이지 나누기가 규칙에서만 허용됩니다.

(귀하의 댓글에 대해golatex.de의 크로스포스트: \cellcolor{gray}이 셀의 숫자도 정렬하려면 중괄호로 묶습니다.)

\documentclass[12pt]{article}
\usepackage[onehalfspacing]{setspace}
\usepackage[american]{babel}
\usepackage{booktabs, multirow, longtable, tabu}
\usepackage{siunitx}
\usepackage[table]{xcolor}
\definecolor{gray}{rgb}{0.8,0.8,0.8}
\usepackage{lipsum}% dummy text
\begin{document}
\lipsum[3]

\begin{longtabu} to \textwidth {X[1.5, l] X[1, l] *{6}{S[table-format=2.3]}}
\toprule
& & \multicolumn{3}{c}{\textbf{def1}} & \multicolumn{3}{c}{\textbf{def2}} \\
\cmidrule(lr){3-5}\cmidrule(lr){6-8}
& & {contrast} & {t} & {p} & {contrast} & {t} & {p} \\ 
\endfirsthead
\toprule
& & \multicolumn{3}{c}{\textbf{def1}} & \multicolumn{3}{c}{\textbf{def2}} \\
& & contrast & t & p & contrast & t & p \\
\midrule[\heavyrulewidth]
\endhead
\multicolumn{8}{r}{continued on the next page} \\
\endfoot
\bottomrule
\endlastfoot

\midrule[\heavyrulewidth]
\multicolumn{8}{c}{\textbf{group1}} \\*
\midrule
\multirow{6}{*}{\textbf{design1}}
& pos1 & 15.05 & 1.06 & 0.145 & -3.41 & -0.28 & 0.610 \\*
& pos2 & 9.20 & 0.65 & 0.258 & -4.02 & -0.32 & 0.627 \\*
& pos3 & 32.92 & 2.30 & {\cellcolor{gray}}0.011 & 4.87 & 0.40 & 0.344 \\*
& pos4 & 6.46 & 0.69 & 0.247 & 3.94 & 0.45 & 0.327 \\*
& pos5 & 10.99 & 0.87 & 0.191 & 0.41 & 0.03 & 0.486 \\*
& pos6 & 36.70 & 2.20 & {\cellcolor{gray}}0.014 & 30.20 & 1.94 & {\cellcolor{gray}}0.026 \\*
\midrule
\multirow{6}{*}{\textbf{design2}}
& pos1 & 6.51 & 0.87 & 0.192 & -2.79 & -0.41 & 0.661 \\*
& pos2 & 1.91 & 0.29 & 0.385 & -3.21 & -0.54 & 0.706 \\*
& pos3 & 16.49 & 2.52 & {\cellcolor{gray}}0.006 & 4.21 & 0.73 & 0.233 \\*
& pos4 & 4.42 & 0.96 & 0.168 & 1.15 & 0.28 & 0.391 \\*
& pos5 & 0.13 & 0.02 & 0.491 & -0.26 & -0.05 & 0.521 \\*
& pos6 & 11.73 & 1.63 & {\cellcolor{gray}}0.052 & 12.18 & 1.88 & {\cellcolor{gray}}0.031 \\*
\midrule
\multirow{6}{*}{\textbf{design3}}
& pos1 & 17.02 & 1.18 & 0.119 & -5.75 & -0.46 & 0.678 \\*
& pos2 & 11.08 & 0.77 & 0.220 & -3.85 & -0.30 & 0.618 \\*% <- remove this * to reproduce the problem
& pos3 & 35.82 & 2.41 & {\cellcolor{gray}}0.008 & 6.00 & 0.48 & 0.316 \\*
& pos4 & 9.59 & 0.96 & 0.170 & 1.78 & 0.19 & 0.423 \\*
& pos5 & 9.25 & 0.70 & 0.243 & 0.86 & 0.07 & 0.472 \\*
& pos6 & 34.91 & 1.99 & {\cellcolor{gray}}0.024 & 32.28 & 2.04 & {\cellcolor{gray}}0.021 \\*
\midrule[\heavyrulewidth]
\multicolumn{8}{c}{\textbf{group2}} \\*
\midrule[\heavyrulewidth]
\multirow{6}{*}{\textbf{design1}}
& pos1 & 16.98 & 1.07 & 0.142 & -10.16 & -0.70 & 0.759 \\*
& pos2 & 18.47 & 1.10 & 0.136 & 2.77 & 0.18 & 0.429 \\*
& pos3 & 15.28 & 1.23 & 0.110 & 16.18 & 1.41 & 0.079 \\*
& pos4 & 21.38 & 1.92 & {\cellcolor{gray}}0.027 & -0.18 & -0.02 & 0.507 \\*
& pos5 & 30.56 & 2.54 & {\cellcolor{gray}}0.006 & 16.49 & 1.50 & 0.067 \\*
& pos6 & 29.32 & 3.40 & {\cellcolor{gray}}0.000 & -7.31 & -0.98 & 0.836 \\*
\midrule
\multirow{6}{*}{\textbf{design2}}
& pos1 & 5.45 & 0.71 & 0.239 & -3.97 & -0.56 & 0.712 \\*
& pos2 & 9.89 & 1.48 & 0.070 & -0.84 & -0.14 & 0.554 \\*
& pos3 & 7.32 & 1.38 & 0.084 & 4.53 & 0.93 & 0.176 \\*
& pos4 & 10.15 & 2.04 & {\cellcolor{gray}}0.021 & -0.86 & -0.19 & 0.575 \\*
& pos5 & 11.09 & 2.20 & {\cellcolor{gray}}0.014 & 3.13 & 0.67 & 0.250 \\*
& pos6 & 9.31 & 1.88 & {\cellcolor{gray}}0.030 & -3.42 & -0.75 & 0.774 \\*
\midrule
\multirow{6}{*}{\textbf{design3}}
& pos1 & 16.54 & 1.06 & 0.145 & -7.81 & -0.55 & 0.709 \\*
& pos2 & 11.86 & 0.72 & 0.236 & -6.58 & -0.43 & 0.667 \\*
& pos3 & 15.75 & 1.29 & 0.099 & 14.89 & 1.32 & 0.093 \\*
& pos4 & 25.87 & 2.36 & {\cellcolor{gray}}0.009 & -1.19 & -0.12 & 0.548 \\*
& pos5 & 30.73 & 2.59 & {\cellcolor{gray}}0.005 & 14.17 & 1.31 & 0.096 \\*
& pos6 & 31.61 & 3.66 & {\cellcolor{gray}}0.000 & -6.28 & -0.85 & 0.802 \\*
\end{longtabu}
\end{document}

여기에 이미지 설명을 입력하세요

다음 그림과 같이 "그룹" 줄 아래의 규칙 뒤에 페이지 나누기가 있을 수 있습니다.

여기에 이미지 설명을 입력하세요

이 경우 수동으로 페이지 나누기를 추가해야 합니다.

\midrule[\heavyrulewidth]\pagebreak
\multicolumn{8}{c}{\textbf{group2}} \\*
\midrule[\heavyrulewidth]

관련 정보