Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to finish this table scheme but I can't figure out what I am doing wrong. I want to convert those discontinued lines into continuous lines and I want to center the label "Total" between the 2 first columns.

\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}

The table output looks like this: enter image description here

Thank you very much for your help!

share|improve this question
    
Welcome to TeX.sx! On this site, a question should typically revolve around an abstract issue (e.g. "How do I get a double horizontal line in a table?") rather than a concrete application (e.g. "How do I make this table?"). Questions that look like "Please do this complicated thing for me" tend to get closed because they are "too localized". Please try to make your question clear and simple by giving a minimal working example (MWE): you'll stand a greater chance of getting help. –  Martin Schröder Jan 2 '13 at 18:13
    
@MartinSchröder You are right, thank you very much for the tips. –  Emer Jan 3 '13 at 7:38
add comment

1 Answer

up vote 9 down vote accepted

enter image description here

\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}
share|improve this answer
2  
I think Emer wanted `\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\% \` in the last block. –  Max Jan 2 '13 at 18:17
1  
@Max thanks, answer updated –  David Carlisle Jan 2 '13 at 18:22
    
Awesome! Thank you guys –  Emer Jan 3 '13 at 7:40
    
I would just remove the | in the following code lines in order to avoid the duplicated segments. \multicolumn{1}{c}{\multirow{2}{}{Cat X1}} & \multicolumn{1}{c}{\multirow{2}{}{Cat X3}} & \multicolumn{1}{c}{\multirow{2}{*}{Cat X3}} & –  Emer Jan 3 '13 at 7:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.