-1

I'm trying to fit table in latex - best sideways on the one page:

    % Table generated by Excel2LaTeX from sheet 'List1'
 \begin{sidewaystable}[htbp]
  \centering
  \caption{Add caption}
    \begin{tabular}{lllrrrrrrrr}
         & \multicolumn{1}{r|}{} & \multicolumn{3}{c|}{\textbf{CNN}} & \multicolumn{3}{c|}{\textbf{CNN-2-opt}} & \multicolumn{4}{c|}{\textbf{PMSOM}} \\
    \multicolumn{1}{c}{\textbf{Instance}} & \multicolumn{1}{c|}{\textbf{Optimum}} & \multicolumn{1}{c}{\textbf{sec1}} & \multicolumn{1}{c}{\textbf{\% rozdíl}} & \multicolumn{1}{c|}{\textbf{\%TPDB}} & \multicolumn{1}{c}{\textbf{sec1}} & \multicolumn{1}{c}{\textbf{\% rozdíl}} & \multicolumn{1}{c|}{\textbf{\%TPDB}} & \multicolumn{1}{c}{\textbf{k*}} & \multicolumn{1}{c}{\textbf{sec1}} & \multicolumn{1}{c}{\textbf{\% rozdíl2}} & \multicolumn{1}{c|}{\textbf{\%TPDB}} \\
    \midrule
    \multicolumn{1}{c}{eil51} & \multicolumn{1}{c|}{426} & \multicolumn{1}{c}{0.019} & \multicolumn{1}{c}{18.78} & \multicolumn{1}{c|}{0.004} & \multicolumn{1}{c}{0.019} & \multicolumn{1}{c}{4.23} & \multicolumn{1}{c|}{0.001} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{0.31} & \multicolumn{1}{c}{1.64} & \multicolumn{1}{c|}{0.005} \\
    \multicolumn{1}{c}{berlin52} & \multicolumn{1}{c|}{7 542} & \multicolumn{1}{c}{0.188} & \multicolumn{1}{c}{8.49} & \multicolumn{1}{c|}{0.016} & \multicolumn{1}{c}{0.019} & \multicolumn{1}{c}{2.53} & \multicolumn{1}{c|}{0.000} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{0.36} & \multicolumn{1}{c}{4.29} & \multicolumn{1}{c|}{0.015} \\
    \multicolumn{1}{c}{eil76} & \multicolumn{1}{c|}{538} & \multicolumn{1}{c}{0.210} & \multicolumn{1}{c}{13.94} & \multicolumn{1}{c|}{0.029} & \multicolumn{1}{c}{0.042} & \multicolumn{1}{c}{7.25} & \multicolumn{1}{c|}{0.003} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{0.67} & \multicolumn{1}{c}{3.72} & \multicolumn{1}{c|}{0.025} \\
    \multicolumn{1}{c}{lin105} & \multicolumn{1}{c|}{14 379} & \multicolumn{1}{c}{0.231} & \multicolumn{1}{c}{17.80} & \multicolumn{1}{c|}{0.041} & \multicolumn{1}{c}{0.094} & \multicolumn{1}{c}{5.30} & \multicolumn{1}{c|}{0.005} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1.11} & \multicolumn{1}{c}{3.00} & \multicolumn{1}{c|}{0.033} \\
    \multicolumn{1}{c}{bier127} & \multicolumn{1}{c|}{118 282} & \multicolumn{1}{c}{0.275} & \multicolumn{1}{c}{13.26} & \multicolumn{1}{c|}{0.036} & \multicolumn{1}{c}{0.145} & \multicolumn{1}{c}{5.76} & \multicolumn{1}{c|}{0.008} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1.53} & \multicolumn{1}{c}{2.40} & \multicolumn{1}{c|}{0.037} \\
    \multicolumn{1}{c}{ch130} & \multicolumn{1}{c|}{6 110} & \multicolumn{1}{c}{0.269} & \multicolumn{1}{c}{17.82} & \multicolumn{1}{c|}{0.048} & \multicolumn{1}{c}{0.190} & \multicolumn{1}{c}{5.09} & \multicolumn{1}{c|}{0.010} & \multicolumn{1}{c}{2} & \multicolumn{1}{c}{4.53} & \multicolumn{1}{c}{2.39} & \multicolumn{1}{c|}{0.108} \\
    \multicolumn{1}{c}{ch150} & \multicolumn{1}{c|}{6 528} & \multicolumn{1}{c}{0.307} & \multicolumn{1}{c}{8.43} & \multicolumn{1}{c|}{0.026} & \multicolumn{1}{c}{0.200} & \multicolumn{1}{c}{2.79} & \multicolumn{1}{c|}{0.006} & \multicolumn{1}{c}{2} & \multicolumn{1}{c}{3.01} & \multicolumn{1}{c}{3.30} & \multicolumn{1}{c|}{0.099} \\
    \multicolumn{1}{c}{rat195} & \multicolumn{1}{c|}{2 323} & \multicolumn{1}{c}{0.431} & \multicolumn{1}{c}{16.92} & \multicolumn{1}{c|}{0.073} & \multicolumn{1}{c}{0.320} & \multicolumn{1}{c}{4.43} & \multicolumn{1}{c|}{0.014} & \multicolumn{1}{c}{2} & \multicolumn{1}{c}{5.70} & \multicolumn{1}{c}{4.09} & \multicolumn{1}{c|}{0.233} \\
    \multicolumn{1}{c}{d198} & \multicolumn{1}{c|}{15 780} & \multicolumn{1}{c}{0.433} & \multicolumn{1}{c}{12.86} & \multicolumn{1}{c|}{0.056} & \multicolumn{1}{c}{0.343} & \multicolumn{1}{c}{4.05} & \multicolumn{1}{c|}{0.014} & \multicolumn{1}{c}{2} & \multicolumn{1}{c}{10.52} & \multicolumn{1}{c}{2.09} & \multicolumn{1}{c|}{0.220} \\
    \multicolumn{1}{c}{pr299} & \multicolumn{1}{c|}{48 191} & \multicolumn{1}{c}{0.873} & \multicolumn{1}{c}{20.95} & \multicolumn{1}{c|}{0.183} & \multicolumn{1}{c}{1.362} & \multicolumn{1}{c}{6.02} & \multicolumn{1}{c|}{0.082} & \multicolumn{1}{c}{2} & \multicolumn{1}{c}{7.81} & \multicolumn{1}{c}{3.99} & \multicolumn{1}{c|}{0.312} \\
    \multicolumn{1}{c}{d493} & \multicolumn{1}{c|}{35 002} & \multicolumn{1}{c}{2.431} & \multicolumn{1}{c}{18.56} & \multicolumn{1}{c|}{0.451} & \multicolumn{1}{c}{5.017} & \multicolumn{1}{c}{5.49} & \multicolumn{1}{c|}{0.275} & \multicolumn{1}{c}{3} & \multicolumn{1}{c}{19.52} & \multicolumn{1}{c}{4.55} & \multicolumn{1}{c|}{0.889} \\
    \multicolumn{1}{c}{u574} & \multicolumn{1}{c|}{36 905} & \multicolumn{1}{c}{3.506} & \multicolumn{1}{c}{20.62} & \multicolumn{1}{c|}{0.723} & \multicolumn{1}{c}{7.651} & \multicolumn{1}{c}{7.83} & \multicolumn{1}{c|}{0.599} & \multicolumn{1}{c}{3} & \multicolumn{1}{c}{30.51} & \multicolumn{1}{c}{3.94} & \multicolumn{1}{c|}{1.201} \\
    \multicolumn{1}{c}{d657} & \multicolumn{1}{c|}{48 912} & \multicolumn{1}{c}{4.950} & \multicolumn{1}{c}{23.63} & \multicolumn{1}{c|}{1.170} & \multicolumn{1}{c}{12.671} & \multicolumn{1}{c}{6.62} & \multicolumn{1}{c|}{0.839} & \multicolumn{1}{c}{3} & \multicolumn{1}{c}{22.22} & \multicolumn{1}{c}{4.32} & \multicolumn{1}{c|}{0.960} \\
    \multicolumn{1}{c}{gr666} & \multicolumn{1}{c|}{294 358} & \multicolumn{1}{c}{4.992} & \multicolumn{1}{c}{26.89} & \multicolumn{1}{c|}{1.342} & \multicolumn{1}{c}{11.810} & \multicolumn{1}{c}{14.60} & \multicolumn{1}{c|}{1.724} & \multicolumn{1}{c}{3} & \multicolumn{1}{c}{28.81} & \multicolumn{1}{c}{9.02} & \multicolumn{1}{c|}{2.598} \\
    \multicolumn{1}{c}{u724} & \multicolumn{1}{c|}{41 910} & \multicolumn{1}{c}{6.410} & \multicolumn{1}{c}{21.94} & \multicolumn{1}{c|}{1.406} & \multicolumn{1}{c}{15.839} & \multicolumn{1}{c}{5.77} & \multicolumn{1}{c|}{0.913} & \multicolumn{1}{c}{3} & \multicolumn{1}{c}{21.41} & \multicolumn{1}{c}{5.30} & \multicolumn{1}{c|}{1.136} \\
    \multicolumn{1}{c}{rat783} & \multicolumn{1}{c|}{8 806} & \multicolumn{1}{c}{7.872} & \multicolumn{1}{c}{21.61} & \multicolumn{1}{c|}{1.701} & \multicolumn{1}{c}{15.748} & \multicolumn{1}{c}{7.81} & \multicolumn{1}{c|}{1.230} & \multicolumn{1}{c}{3} & \multicolumn{1}{c}{14.55} & \multicolumn{1}{c}{6.15} & \multicolumn{1}{c|}{0.896} \\
    1) stanoveno jako průměr z 10 měření &      &      & \multicolumn{1}{c}{\textbf{17.66}} & \multicolumn{1}{c}{\textbf{0.46}} &      & \multicolumn{1}{c}{\textbf{5.97}} & \multicolumn{1}{c}{\textbf{0.36}} &      &      & \multicolumn{1}{c}{\textbf{4.01}} & \multicolumn{1}{c}{\textbf{0.55}} \\
    \multicolumn{3}{l}{2) dle nejlepší hodnoty z 10 měření} &      &      &      &      &      &      &      &      &  \\
    \bottomrule
    \end{tabular}%
  \label{tab:addlabel}%
\end{sidewaystable}%
  • Please make a comilable minimal working example (MWE) that included the documentclass and the relevant packages. – leandriis Apr 2 at 20:59
  • Please also add information on the desired alignment in the last two rows. Addionally, you might want to remove the vertical lines as the horizontal lines from the booktbas package (that you use) don't cooperate well with vertical lines. – leandriis Apr 2 at 21:02
  • Consider accepting one of the provided answers. – Dr. Manuel Kuehner Jun 21 at 18:28
2

Two possible solutions:

I have removed the vertical lines, added some horizontal lines to the header, adjusted the tabcolsep to make the table fit the page, removed superfluous multicolumn commands (and used siunitx for the alignment of numbers with respect to their decimal separator in the second table) ...

\documentclass{article}

\usepackage{rotating}
\usepackage{booktabs}

\usepackage[detect-all]{siunitx}
\usepackage{etoolbox}
\robustify\bfseries

\begin{document}

 \begin{sidewaystable} [htbp]
 \setlength{\tabcolsep}{4pt}
  \centering
  \caption{Add caption} 
    \begin{tabular}{lllccccccccc}
    \toprule
         & & \multicolumn{3}{c}{\textbf{CNN}}   & \multicolumn{3}{c}{\textbf{CNN-2-opt}} & \multicolumn{4}{c}{\textbf{PMSOM}}   \\
         \cmidrule(r){3-5} \cmidrule(lr){6-8} \cmidrule(l){9-12}
    \multicolumn{1}{c}{\textbf{Instance}}   & \multicolumn{1}{c}{\textbf{Optimum}}   &  \textbf{sec1}   &  \textbf{\% rozdíl}   & \multicolumn{1}{c}{\textbf{\%TPDB}}   &  \textbf{sec1 }  &  \textbf{\% rozdíl}   & \multicolumn{1}{c}{\textbf{\%TPDB }}  &  \textbf{k* }  &  \textbf{sec1}   &  \textbf{\% rozdíl2}   & \multicolumn{1}{c}{\textbf{\%TPDB}}   \\
    \midrule
     eil51  & 426  &  0.019  &  18.78  &   0.004  &  0.019  &  4.23  &   0.001  &  1  &  0.31  &  1.64  &   0.005  \\
     berlin52  &   7 542  &  0.188  &  8.49  &   0.016  &  0.019  &  2.53  &   0.000  &  1  &  0.36  &  4.29  &   0.015  \\
     eil76  &   538  &  0.210  &  13.94  &   0.029  &  0.042  &  7.25  &   0.003  &  1  &  0.67  &  3.72  &   0.025  \\
     lin105  &   14 379  &  0.231  &  17.80  &   0.041  &  0.094  &  5.30  &   0.005  &  1  &  1.11  &  3.00  &   0.033  \\
     bier127  &   118 282  &  0.275  &  13.26  &   0.036  &  0.145 &  5.76  &   0.008  &  1  &  1.53  &  2.40  &   0.037  \\
     ch130  &   6 110  &  0.269  &  17.82  &   0.048  &  0.190  &  5.09  &   0.010  &  2  &  4.53  &  2.39  &   0.108  \\
     ch150  &   6 528  &  0.307  &  8.43  &   0.026  &  0.200  &  2.79  &   0.006  &  2  &  3.01  &  3.30  &   0.099  \\
     rat195  &   2 323  &  0.431  &  16.92  &   0.073  &  0.320  &  4.43  &   0.014  &  2  &  5.70  &  4.09  &   0.233  \\
     d198  &   15 780  &  0.433  &  12.86  &   0.056  &  0.343  &  4.05  &   0.014  &  2  &  10.52  &  2.09  &   0.220  \\
     pr299  &   48 191  &  0.873  &  20.95  &   0.183  &  1.362  &  6.02  &   0.082  &  2  &  7.81  &  3.99  &   0.312  \\
     d493  &   35 002  &  2.431  &  18.56  &   0.451  &  5.017  &  5.49  &   0.275  &  3  &  19.52  &  4.55  &   0.889  \\
     u574  &   36 905  &  3.506  &  20.62  &   0.723  &  7.651  &  7.83  &   0.599  &  3  &  30.51  &  3.94  &   1.201  \\
     d657  &   48 912  &  4.950  &  23.63  &   1.170  &  12.671  &  6.62  &   0.839  &  3  &  22.22  &  4.32  &   0.960  \\
     gr666  &   294 358  &  4.992  &  26.89  &   1.342  &  11.810  &  14.60  &   1.724  &  3  &  28.81  &  9.02  &   2.598  \\
     u724  &   41 910  &  6.410  &  21.94  &   1.406  &  15.839  &  5.77  &   0.913  &  3  &  21.41  &  5.30  &   1.136  \\
     rat783  &   8 806  &  7.872  &  21.61  &   1.701  &  15.748  &  7.81  &   1.230  &  3  &  14.55  &  6.15  &   0.896  \\
& &     &  \textbf{17.66 }  &  \textbf{0.46 }  &      &  \textbf{5.97 }  &  \textbf{0.36  } &      &      &  \textbf{4.01}   &  \textbf{0.55}   \\
    \multicolumn{12}{l}{1) stanoveno jako průměr z 10 měření} \\
    \multicolumn{12}{l}{2) dle nejlepší hodnoty z 10 měření} \\
    \bottomrule
    \end{tabular} %
  \label{tab:addlabel} %
\end{sidewaystable} %

 \begin{sidewaystable} [htbp]
 \setlength{\tabcolsep}{4pt}
  \centering
  \caption{Add caption} 
    \begin{tabular}{l
                    S[table-format=6,group-four-digits]
                    S[table-format=1.3]
                    S[table-format=2.2,detect-weight]
                    S[table-format=1.3,detect-weight]
                    S[table-format=2.3]
                    S[table-format=2.3,detect-weight]
                    S[table-format=2.3,detect-weight]
                    c
                    S[table-format=2.2]
                    S[table-format=1.2,detect-weight]
                    S[table-format=1.3,detect-weight]}
    \toprule
         & & \multicolumn{3}{c}{\textbf{CNN}}   & \multicolumn{3}{c}{\textbf{CNN-2-opt}} & \multicolumn{4}{c}{\textbf{PMSOM}}   \\
         \cmidrule(r){3-5} \cmidrule(lr){6-8} \cmidrule(l){9-12}
    \multicolumn{1}{c}{\textbf{Instance}}   & \multicolumn{1}{c}{\textbf{Optimum}}   &  \textbf{sec1}   &  \textbf{\% rozdíl}   & \multicolumn{1}{c}{\textbf{\%TPDB}}   &  \textbf{sec1 }  &  \textbf{\% rozdíl}   & \multicolumn{1}{c}{\textbf{\%TPDB }}  &  \textbf{k* }  &  \textbf{sec1}   &  \textbf{\% rozdíl2}   & \multicolumn{1}{c}{\textbf{\%TPDB}}   \\
    \midrule
     eil51  & 426  &  0.019  &  18.78  &   0.004  &  0.019  &  4.23  &   0.001  &  1  &  0.31  &  1.64  &   0.005  \\
     berlin52  &   7 542  &  0.188  &  8.49  &   0.016  &  0.019  &  2.53  &   0.000  &  1  &  0.36  &  4.29  &   0.015  \\
     eil76  &   538  &  0.210  &  13.94  &   0.029  &  0.042  &  7.25  &   0.003  &  1  &  0.67  &  3.72  &   0.025  \\
     lin105  &   14 379  &  0.231  &  17.80  &   0.041  &  0.094  &  5.30  &   0.005  &  1  &  1.11  &  3.00  &   0.033  \\
     bier127  &   118 282  &  0.275  &  13.26  &   0.036  &  0.145 &  5.76  &   0.008  &  1  &  1.53  &  2.40  &   0.037  \\
     ch130  &   6 110  &  0.269  &  17.82  &   0.048  &  0.190  &  5.09  &   0.010  &  2  &  4.53  &  2.39  &   0.108  \\
     ch150  &   6 528  &  0.307  &  8.43  &   0.026  &  0.200  &  2.79  &   0.006  &  2  &  3.01  &  3.30  &   0.099  \\
     rat195  &   2 323  &  0.431  &  16.92  &   0.073  &  0.320  &  4.43  &   0.014  &  2  &  5.70  &  4.09  &   0.233  \\
     d198  &   15 780  &  0.433  &  12.86  &   0.056  &  0.343  &  4.05  &   0.014  &  2  &  10.52  &  2.09  &   0.220  \\
     pr299  &   48 191  &  0.873  &  20.95  &   0.183  &  1.362  &  6.02  &   0.082  &  2  &  7.81  &  3.99  &   0.312  \\
     d493  &   35 002  &  2.431  &  18.56  &   0.451  &  5.017  &  5.49  &   0.275  &  3  &  19.52  &  4.55  &   0.889  \\
     u574  &   36 905  &  3.506  &  20.62  &   0.723  &  7.651  &  7.83  &   0.599  &  3  &  30.51  &  3.94  &   1.201  \\
     d657  &   48912  &  4.950  &  23.63  &   1.170  &  12.671  &  6.62  &   0.839  &  3  &  22.22  &  4.32  &   0.960  \\
     gr666  &   294358  &  4.992  &  26.89  &   1.342  &  11.810  &  14.60  &   1.724  &  3  &  28.81  &  9.02  &   2.598  \\
     u724  &   41 910  &  6.410  &  21.94  &   1.406  &  15.839  &  5.77  &   0.913  &  3  &  21.41  &  5.30  &   1.136  \\
     rat783  &   8806  &  7.872  &  21.61  &   1.701  &  15.748  &  7.81  &   1.230  &  3  &  14.55  &  6.15  &   0.896  \\
& &     &  \bfseries 17.66  &  \bfseries 0.46  &      &  \bfseries 5.97  &  \bfseries 0.36 &      &      &  \bfseries 4.01   &  \bfseries 0.55   \\
    \multicolumn{12}{l}{1) stanoveno jako průměr z 10 měření} \\
    \multicolumn{12}{l}{2) dle nejlepší hodnoty z 10 měření} \\
    \bottomrule
    \end{tabular} %
  \label{tab:addlabel} %
\end{sidewaystable} %

\end{document}

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.