1

I am a beginner in LaTeX and have to make some very sophisticated tables in it. I use help from TeX.SE to complete the jobs of drawing these difficult tables.

This time I have been stuck with a table: Everything is working fine except a column (no. 8) is too wide. I have tried some tricks but nothing worked this time. Can anybody please help me to fix this problem?

\documentclass[a4paper,10pt]{article} 

\usepackage{graphicx}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{longtable}
\usepackage{tabu}
\usepackage{pdflscape}
\usepackage{footnote}

\begin{document}
\begin{landscape}
\begin{center}
\begin{savenotes}
{\renewcommand{\arraystretch}{1.1}
\begin{longtable}{|*{4}{c@{\hskip1pt}|}|*{4}{c@{\hskip1pt}|}|*{1}{c@{\hskip1pt}|}|*{3}{c@{\hskip1pt}|}|*{3}{c@{\hskip1pt}|}|*{1}{c@{\hskip1pt}|}}
\hline

{\bf \multirow{3}{*}{\rotatebox[origin=c]{90}{Nodes}}}& {\bf \multirow{3}{*}{\rotatebox[origin=c]{90}{Clusters}}}& \multirow{3}{1cm}{${|E^*|}$}& \multirow{3}{1.2cm}{\bf{\%age gap of} ${|E_{heu}|}$}& \multicolumn{4}{c|}{\bf \small Percentage of Clusters removed by}& \multirow{3}{1.4cm}{\small \bf No. of nodes removed}& \multicolumn{7}{c|}{\bf \small Time for computing solution (in seconds)}  \\\cline{5-8} \cline{10-16}


 & & &  & \multirow{2}{1cm}{Red 1\&2}& \multirow{2}{1cm}{Red 3}& \multirow{2}{1cm}{Red 4}& \multirow{2}{1cm}{Red 5}& & \multicolumn{3}{c|}{\bf {Before reductions}}& \multicolumn{3}{c|}{\bf {After reductions}}& \multirow{2}{1cm}{\bf {heu}}\\\cline{10-15}

& & &  &  & & & & & inr & rf-inr & imp & inr & rf-inr& imp&  \\\hline


\multirow{3}{*}{6}& 6& 6.00& 0.00& 31.67& 16.67& 0.00& 0.00& 2.80& 0.03& 0.02& 0.02& 0.00& 0.01& 0.01& 0.01\\
  & 18& 8.40& 7.14& 1.67& 42.78& 0.00& 0.00& 0.10& 0.03& 0.04& 0.03& 0.02& 0.02& 0.02& 0.02\\
  & 30& 10.40& 2.88& 0.00& 56.00& 0.67& 0.00& 0.00& 0.06& 0.05& 0.05& 0.02& 0.02& 0.02& 0.03\\\hline
\multirow{3}{*}{8}& 8& 8.00& 1.25& 37.50& 16.25& 0.00& 0.00& 4.30& 0.06& 0.06& 0.03& 0.01& 0.01& 0.01& 0.01\\
  & 24& 12.10& 9.09& 0.00& 37.08& 0.00& 0.00& 0.00& 0.11& 0.09& 0.07& 0.05& 0.05& 0.04& 0.03\\
  & 40& 14.60& 12.33& 0.00& 50.25& 0.00& 0.00& 0.00& 0.23& 0.13& 0.10& 0.06& 0.05& 0.04& 0.06\\\hline

\end{longtable}
}
\end{savenotes}
\end{center}
\end{landscape}
\end{document}

See the attached image

2
  • 1
    Welcome to TeX.SE! column 8 is to wide because text "Percentage of Clusters removed by" is to wide and consequently expand width of last column over which it is span. A question: does you really need long table (is table more page long)?
    – Zarko
    Mar 20, 2017 at 15:54
  • Yes @Zarko the table is more than one page long. Sometimes the table spans more than 3 pages as well. But I am unable to find the solution from your description. Is it really possible to fix the width for the statement "Percentage of Clusters removed by". Mar 20, 2017 at 16:11

2 Answers 2

2

I would like to suggest that you streamline and simplify much of the code in the longtable environment. I would also like to suggest that you not use boldface at all; it's not needed -- really. Double vertical lines aren't needed either.

enter image description here

\documentclass[a4paper,10pt]{article} 

\usepackage{graphicx}
\usepackage{multirow}
\usepackage{longtable}
\usepackage{pdflscape} % for 'landscape' env.
\usepackage{footnote}  % for 'savenotes' env. 

\begin{document}
\begin{landscape}
\centering
\begin{savenotes}
\renewcommand{\arraystretch}{1.1}
\setlength\tabcolsep{4pt}
\begin{longtable}{|*{16}{c|}}
\hline

\multirow{3}{*}{\rotatebox[origin=c]{90}{Nodes}}& 
\multirow{3}{*}{\rotatebox[origin=c]{90}{Clusters}} & 
\multirow{3}{*}{$|E^*|$}& 
   \multirow{3}{1.2cm}{{\% age gap of $|E_{heu}|$}}& 
   \multicolumn{4}{c|}{\small Percent.\ of clusters removed by}& 
   \multirow{3}{1.3cm}{\small No.\ of nodes removed}& 
   \multicolumn{7}{c|}{\small Time for computing solution (in seconds)}  \\
   \cline{5-8} \cline{10-16}
 & & & & 
 \multirow{2}{1cm}{Red 1\&2}& 
 \multirow{2}{1cm}{Red 3}& 
 \multirow{2}{1cm}{Red 4}& 
 \multirow{2}{1cm}{Red 5}& & 
 \multicolumn{3}{c|}{\small Before reductions}& 
 \multicolumn{3}{c|}{\small After reductions}& 
 \multirow{2}{*}{heu}\\
 \cline{10-15}
& & & & & & & & & inr & rf-inr & imp & inr & rf-inr& imp & \\
\hline\hline
\endhead

\hline
\endfoot

\multirow{3}{*}{6}& 6& 6.00& 0.00& 31.67& 16.67& 0.00& 0.00& 2.80& 0.03& 0.02& 0.02& 0.00& 0.01& 0.01& 0.01\\
  & 18& 8.40& 7.14& 1.67& 42.78& 0.00& 0.00& 0.10& 0.03& 0.04& 0.03& 0.02& 0.02& 0.02& 0.02\\
  & 30& 10.40& 2.88& 0.00& 56.00& 0.67& 0.00& 0.00& 0.06& 0.05& 0.05& 0.02& 0.02& 0.02& 0.03\\
\hline
\multirow{3}{*}{8}& 8& 8.00& 1.25& 37.50& 16.25& 0.00& 0.00& 4.30& 0.06& 0.06& 0.03& 0.01& 0.01& 0.01& 0.01\\
  & 24& 12.10& 9.09& 0.00& 37.08& 0.00& 0.00& 0.00& 0.11& 0.09& 0.07& 0.05& 0.05& 0.04& 0.03\\
  & 40& 14.60& 12.33& 0.00& 50.25& 0.00& 0.00& 0.00& 0.23& 0.13& 0.10& 0.06& 0.05& 0.04& 0.06\\
\end{longtable}
\end{savenotes}
\end{landscape}
\end{document}
0
2

As supplement to Mico answer:

enter image description here

\documentclass[a4paper,10pt]{article}

\usepackage{graphicx}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{longtable}
\usepackage{tabu}
\usepackage{pdflscape}
\usepackage{footnote}

\usepackage{booktabs, makecell, rotating}% <-- added
\settowidth\rotheadsize{\theadfont Clusters}% <-- added

\usepackage{siunitx}

\begin{document}
\begin{landscape}
\begin{center}
\begin{savenotes}
{\renewcommand{\arraystretch}{1.1}
 \setlength\tabcolsep{4pt}
\begin{longtable}{c  % <-- new columns definition, based on siunitx
                  S[table-format=2.0]
             *{4}{S[table-column-width=11mm,
                    table-format=2.2]}
            *{10}{S[table-column-width=11mm,
                    table-format=1.2]}
                 }
    \toprule % <-- from booktabs
\multirow[b]{3}{*}[1ex]{\rothead{Nodes}}% <-- from makecell
    & {\multirow[b]{3}{*}[1ex]{\rothead{Clusters}}}
    & {\multirow[b]{3}{1cm}[-1ex]{$|E^*|$}}
    & {\multirow[b]{3}{1.2cm}[-1ex]{\%age gap of $|E_{heu}|$}}
    & \multicolumn{4}{c}{Percentage of Clusters removed by}
    & {\multirow[b]{3}{1.4cm}[-1ex]{No. of nodes removed}}
    & \multicolumn{7}{c}{Time for computing solution (in seconds)}  \\
    \cmidrule(lr){5-8} \cmidrule(l){10-16}
 & & &  & {\multirow{2}{*}{\makecell{Red\\ 1\&2}}}
        & {\multirow[b]{2}{*}{Red 3}}
        & {\multirow[b]{2}{*}{Red 4}}
        & {\multirow[b]{2}{*}{Red 5}}
          & & \multicolumn{3}{c}{Before reductions}
            & \multicolumn{3}{c}{After reductions}
            & {\multirow{2}{1cm}{heu}}  \\
    \cmidrule(lr){10-12} \cmidrule(lr){13-15}
 & & &  &  & & & & & {inr} & {rf-inr} & {imp} & {inr} & {rf-inr} & {imp} &  \\
    \midrule
\multirow{3}{*}{6}
 & 6& 6.00& 0.00& 31.67& 16.67& 0.00& 0.00& 2.80& 0.03& 0.02& 0.02& 0.00& 0.01& 0.01& 0.01\\
 & 18& 8.40& 7.14& 1.67& 42.78& 0.00& 0.00& 0.10& 0.03& 0.04& 0.03& 0.02& 0.02& 0.02& 0.02\\
 & 30& 10.40& 2.88& 0.00& 56.00& 0.67& 0.00& 0.00& 0.06& 0.05& 0.05& 0.02& 0.02& 0.02& 0.03\\
    \midrule
\multirow{3}{*}{8}
 & 8& 8.00& 1.25& 37.50& 16.25& 0.00& 0.00& 4.30& 0.06& 0.06& 0.03& 0.01& 0.01& 0.01& 0.01\\
 & 24& 12.10& 9.09& 0.00& 37.08& 0.00& 0.00& 0.00& 0.11& 0.09& 0.07& 0.05& 0.05& 0.04& 0.03\\
 & 40& 14.60& 12.33& 0.00& 50.25& 0.00& 0.00& 0.00& 0.23& 0.13& 0.10& 0.06& 0.05& 0.04& 0.06\\
    \bottomrule
\end{longtable}
}
\end{savenotes}
\end{center}
\end{landscape}
\end{document}

Maybe you will like this more professional looks of table

Note: your basic problem can be solved on two ways:

  • broke text in \multicolumn{4}{c}{Percentage of Clusters removed by} into two line, that the width of multicolumn is smaller than sum of spanned columns widths and preserve your column definitions
  • or change column definition as suggested Mico and it is further elaborate in this answer
4
  • Thanks @Zarko your description is also a solution to my problem. But I would appreciate if you can give some hint on which table environment is better for such tables. Always the limitation of one environment forces me to use some other. So I have to switch between different environments. Mar 22, 2017 at 12:44
  • @OptimistOptimizer, LaTeX provide many table environments, each is dedicated to specific problem. In above case the tabularx is the best solution (to my opinion) because: (i) it itself calculate column width, (ii) has prescribed width, (iii) columns are of paragraph type (not very relevant for this table). I believe, that stick with two table environments (tabular and tabularx) in your document and also switch from one to other, is not big deal :). In this case you need only to change tabular to tabularx, determine table width and that that is.
    – Zarko
    Mar 22, 2017 at 13:22
  • OK. I have another difficulty that your provided solution does not work if I use <vpos> ([b]) for multirow. So I have to remove all [b] in the above provided solution for a successful compilation. I suspect that I need some extra package for this. Mar 22, 2017 at 13:43
  • @OptimistOptimizer, it seems that you have old version of ˙multirow` packages. I strongly encourage you to upgrade your LaTeX installation to the recent version.
    – Zarko
    Mar 22, 2017 at 14:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .