17

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!

  • 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
23

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}
| 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
  • 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
  • I cannot compile this with pdflatex. – Elias Feb 17 '17 at 9:52
  • @Elias this has been corrupted by a bug on the site we have repeatedly asked for the bug to be fixed but no response so far, I wil fix it and ping you in a few minutes see meta.tex.stackexchange.com/questions/7168/… – David Carlisle Feb 17 '17 at 10:26
  • 1
    @Elias I have restored the answer to working version. – David Carlisle Feb 17 '17 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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