我正在尝试完成这个表格方案,但我不知道我做错了什么。我想将这些不连续的线转换为连续的线,并希望将标签“总计”置于前两列之间。
\documentclass[a4paper]{article}
\usepackage{longtable}
\usepackage{rotating}
\usepackage{array}
\usepackage{multicol}
\usepackage{multirow}
\begin{document}
\begin{longtable}[c]{ccc|c|c|c|c|}
\cline{4-7}
& & & \multicolumn{4}{c|}{Var Y} \\
\cline{4-7}
& & &
\begin{sideways} Cat Y1 \end{sideways} &
\begin{sideways} Cat Y2 \end{sideways} &
\begin{sideways} Cat Y3 \end{sideways} &
\begin{sideways} Cat Y4 \end{sideways} \\
\hline \multirow{6}{*}{\begin{sideways}Var X\end{sideways}} &
\multicolumn{1}{|c}{\multirow{2}{*}{Cat X1}} &
\multicolumn{1}{c|}{N} & 4 & & & \\
\multicolumn{1}{|c}{} & &
\multicolumn{1}{c|}{\%} & 100.00\% & & & \\
\cline{2-7} &
\multicolumn{1}{|c}{\multirow{2}{*}{Cat X2}} &
\multicolumn{1}{c|}{N} & & 7 & 3 & \\
\multicolumn{1}{|c}{} & &
\multicolumn{1}{c|}{\%}& & 70.00\% & 30.00\% & \\ \cline{2-7} &
\multicolumn{1}{|c}{\multirow{2}{*}{Cat X3}} &
\multicolumn{1}{c|}{N} & & 25 & & 10 \\
\multicolumn{1}{|c}{} & &
\multicolumn{1}{c|}{\%}& & 71.43\% & & 28.57\% \\
\hline &
\multicolumn{1}{c}{\multirow{2}{*}{Total}} &
%\multicolumn{1}{|c}{\multirow{2}{*}{\multicolumn{2}{c}{Total} }} &
\multicolumn{1}{c|}{N} & 4 & 23 & 3 & 10 \\
\multicolumn{1}{|c}{} & &
\multicolumn{1}{c|}{\%}& 10.00\% & 57.50\% & 7.50\% & 2.50\% \\
\hline
\end{longtable}
\end{document}
表格输出如下所示:
非常感谢您的帮助!
答案1
\documentclass[a4paper]{article}
\usepackage{longtable}
\usepackage{rotating}
\usepackage{array}
\usepackage{multicol}
\usepackage{multirow}
\begin{document}
\setlength\extrarowheight{3pt}
\begin{longtable}[c]{|c|cc|c|c|c|c|}
\cline{4-7}
\multicolumn{2}{c}{}& & \multicolumn{4}{c|}{Var Y} \\
\cline{4-7}
\multicolumn{2}{c}{}& &
\rotatebox{90}{Cat Y1\ }&
\rotatebox{90}{Cat Y2\ }&
\rotatebox{90}{Cat Y3\ }&
\rotatebox{90}{Cat Y4\ }\\
\hline \multirow{6}{*}{\begin{sideways}Var X\end{sideways}} &
\multicolumn{1}{|c}{\multirow{2}{*}{Cat X1}} &
\multicolumn{1}{c|}{N} & 4 & & & \\
\multicolumn{1}{|c|}{} & &
\multicolumn{1}{c|}{\%} & 100.00\% & & & \\
\cline{2-7} &
\multicolumn{1}{|c}{\multirow{2}{*}{Cat X2}} &
\multicolumn{1}{c|}{N} & & 7 & 3 & \\
\multicolumn{1}{|c|}{} & &
\multicolumn{1}{c|}{\%}& & 70.00\% & 30.00\% & \\
\cline{2-7} &
\multicolumn{1}{|c}{\multirow{2}{*}{Cat X3}} &
\multicolumn{1}{c|}{N} & & 25 & & 10 \\
\multicolumn{1}{|c|}{} & &
\multicolumn{1}{c|}{\%}& & 71.43\% & & 28.57\% \\
\hline
\multicolumn{2}{|c}{\multirow{2}{*}{Total}} &
\multicolumn{1}{c|}{N} & 4 & 23 & 3 & 10 \\
\multicolumn{2}{|c}{} &
\multicolumn{1}{c|}{\%}& 10.00\% & 57.50\% & 7.50\% & 2.50\% \\
\hline
\end{longtable}
\end{document}