旋转的表格超出了文本块的宽度

旋转的表格超出了文本块的宽度

我有一个表格(代码在最后),它逆时针旋转了 90 度。但是,它太宽了。我该如何解决这个问题(适合(旋转的)文本块的宽度)?一种解决方案可能是将前两列设为多行列,但我没有成功。

\begin{sidewaystable}
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{ccccccccccccccccc}
\hline
\multicolumn{1}{|c|}{\multirow{3}{*}{Algorithm}}         & \multicolumn{1}{c|}{\multirow{3}{*}{Prediction Method}} & \multicolumn{15}{c|}{PH (min)}                                                                                                                                                                                                                                                                                                                                                                                                                                \\ \cline{3-17} 
\multicolumn{1}{|c|}{}                                   & \multicolumn{1}{c|}{}                                   & \multicolumn{3}{c|}{10}                                                                & \multicolumn{3}{c|}{20}                                                                 & \multicolumn{3}{c|}{30}                                                                 & \multicolumn{3}{c|}{45}                                                                 & \multicolumn{3}{c|}{60}                                                                \\ \cline{3-17} 
\multicolumn{1}{|c|}{}                                   & \multicolumn{1}{c|}{}                                   & \multicolumn{1}{c|}{W}  & \multicolumn{1}{c|}{RMSE} & \multicolumn{1}{c|}{$R_{adj}^2$} & \multicolumn{1}{c|}{W}  & \multicolumn{1}{c|}{RMSE}  & \multicolumn{1}{c|}{$R_{adj}^2$} & \multicolumn{1}{c|}{W}  & \multicolumn{1}{c|}{RMSE}  & \multicolumn{1}{c|}{$R_{adj}^2$} & \multicolumn{1}{c|}{W}  & \multicolumn{1}{c|}{RMSE}  & \multicolumn{1}{c|}{$R_{adj}^2$} & \multicolumn{1}{c|}{W}  & \multicolumn{1}{c|}{RMSE}  & \multicolumn{1}{c|}{Adj.~$r^2$} \\ \hline
\multicolumn{1}{|c|}{Naive}                              & \multicolumn{1}{c|}{-}                                  & \multicolumn{1}{c|}{49} & \multicolumn{1}{c|}{7.43} & \multicolumn{1}{c|}{0.90}        & \multicolumn{1}{c|}{49} & \multicolumn{1}{c|}{13.40} & \multicolumn{1}{c|}{0.69}        & \multicolumn{1}{c|}{49} & \multicolumn{1}{c|}{17.82} & \multicolumn{1}{c|}{0.45}        & \multicolumn{1}{c|}{49} & \multicolumn{1}{c|}{21.53} & \multicolumn{1}{c|}{0.16}        & \multicolumn{1}{c|}{49} & \multicolumn{1}{c|}{22.75} & \multicolumn{1}{c|}{0.00}       \\ \hline
\multicolumn{1}{|c|}{\multirow{2}{*}{Linear Regression}} & \multicolumn{1}{c|}{Direct}                             & \multicolumn{1}{c|}{34} & \multicolumn{1}{c|}{5.10} & \multicolumn{1}{c|}{0.96}        & \multicolumn{1}{c|}{19} & \multicolumn{1}{c|}{11.03} & \multicolumn{1}{c|}{0.82}        & \multicolumn{1}{c|}{19} & \multicolumn{1}{c|}{16.08} & \multicolumn{1}{c|}{0.62}        & \multicolumn{1}{c|}{16} & \multicolumn{1}{c|}{20.87} & \multicolumn{1}{c|}{0.36}        & \multicolumn{1}{c|}{40} & \multicolumn{1}{c|}{21.92} & \multicolumn{1}{c|}{0.16}       \\ \cline{2-17} 
\multicolumn{1}{|c|}{}                                   & \multicolumn{1}{c|}{Iterative}                          & \multicolumn{1}{c|}{34} & \multicolumn{1}{c|}{5.10} & \multicolumn{1}{c|}{0.96}        & \multicolumn{1}{c|}{19} & \multicolumn{1}{c|}{11.03} & \multicolumn{1}{c|}{0.82}        & \multicolumn{1}{c|}{19} & \multicolumn{1}{c|}{16.00} & \multicolumn{1}{c|}{0.62}        & \multicolumn{1}{c|}{37} & \multicolumn{1}{c|}{20.71} & \multicolumn{1}{c|}{0.30}        & \multicolumn{1}{c|}{43} & \multicolumn{1}{c|}{21.58} & \multicolumn{1}{c|}{0.16}       \\ \hline
\multicolumn{1}{|c|}{}                                   & \multicolumn{1}{c|}{}                                   & \multicolumn{1}{c|}{}   & \multicolumn{1}{c|}{}     & \multicolumn{1}{c|}{}            & \multicolumn{1}{c|}{}   & \multicolumn{1}{c|}{}      & \multicolumn{1}{c|}{}            & \multicolumn{1}{c|}{}   & \multicolumn{1}{c|}{}      & \multicolumn{1}{c|}{}            & \multicolumn{1}{c|}{}   & \multicolumn{1}{c|}{}      & \multicolumn{1}{c|}{}            & \multicolumn{1}{c|}{}   & \multicolumn{1}{c|}{}      & \multicolumn{1}{c|}{}           \\ \hline
                                                         &                                                         &                         &                           &                                  &                         &                            &                                  &                         &                            &                                  &                         &                            &                                  &                         &                            &                                 \\
\end{tabular}
\end{sidewaystable}

EDIT1:我的序言是:

\usepackage[usenames,dvipsnames,table]{xcolor}

\usepackage[square, numbers, comma, sort&compress]{natbib} % Use the natbib reference package - read up on this to edit the reference style; if you want text (e.g. Smith et al., 2012) for the in-text references (instead of numbers), remove 'numbers' 
\hypersetup{urlcolor=blue, colorlinks=true} % Colors hyperlinks in blue - change to black if annoying
\title{\ttitle} % Defines the thesis title - don't touch this


%\usepackage[disable]{todonotes}
\usepackage[draft]{todonotes}


\usepackage[bottom]{footmisc}
\usepackage[export]{adjustbox}

\usepackage{multirow}
\usepackage{pgfgantt}
\usepackage{fixltx2e}
\usepackage{cals}
\usepackage{rotating}
\usepackage{array}

\usepackage[showframe, nomarginpar]{geometry}
\usepackage{graphics}
\usepackage{amsmath}
\usepackage{caption, makecell}
\setcellgapes{4pt}

答案1

您可以使用该包将一些列标题设为双行makecell。我借此机会为表格添加了一些垂直填充,并简化了代码,只保留了必要的\multicolumn部分。加载该caption包使标题和表格之间的垂直(?)间距更加合理。

\documentclass[a4paper, twoside]{Thesis}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{makecell}
\setcellgapes{4pt}
\usepackage[usenames,dvipsnames,table]{xcolor}

\usepackage[square, numbers, comma, sort&compress]{natbib} % Use the natbib reference package - read up on this to edit the reference style; if you want text (e.g. Smith et al., 2012) for the in-text references (instead of numbers), remove 'numbers'
\title{\ttitle} % Defines the thesis title - don't touch this


%\usepackage[disable]{todonotes}
\usepackage[draft]{todonotes}


\usepackage[bottom]{footmisc}
\usepackage[export]{adjustbox}

\usepackage{multirow}
%\usepackage{pgfgantt}
%\usepackage{cals}
\usepackage{rotating}
\usepackage{array}

\usepackage[showframe, nomarginpar]{geometry}
\usepackage{graphics}%graphicx
\usepackage{amsmath}
\usepackage{caption, makecell}
\setcellgapes{4pt}
\usepackage{hyperref}
\hypersetup{urlcolor=blue, colorlinks=true} % Colors hyperlinks in blue - change to black if annoying

\begin{document}

\begin{sidewaystable}
  \centering \makegapedcells%
  \setlength\tabcolsep{5pt}
  \caption{My caption}
  \label{my-label}
  \begin{tabular}{|*{17}{c|}}
    \hline
    \multirowcell{3}[-1.5ex]{Algorithm} & \multirowcell{3}[-1.5ex]{Prediction\\ Method} & \multicolumn{15}{c|}{PH (min)} \\
    \cline{3-17}
    \multicolumn{1}{|c|}{}& \multicolumn{1}{c|}{} & \multicolumn{3}{c|}{10} & \multicolumn{3}{c|}{20} & \multicolumn{3}{c|}{30} & \multicolumn{3}{c|}{45} & \multicolumn{3}{c|}{60} \\
    \cline{3-17}
    \multicolumn{1}{|c|}{} & \multicolumn{1}{c|}{} & W & RMSE & $R_\text{adj}^2$ & W & RMSE & $R_\text{adj}^2$ & W & RMSE & $R_\text{adj}^2$ & W & RMSE & $R_\text{adj}^2$ & W & RMSE & Adj.~$r^2$ \\
    \hline
    \multicolumn{1}{|c|}{Naive} & --- & 49 & 7.43 & 0.90 & 49 & 13.40 & 0.69 & 49 & 17.82 & 0.45 & 49 & 21.53 & 0.16 & 49 & 22.75 & 0.00 \\
    \hline
    \multicolumn{1}{|c|}{\multirowcell{2}{Linear \\ Regression}} & Direct & 34 & 5.10 & 0.96 & 19 & 11.03 & 0.82 & 19 & 16.08 & 0.62 & 16 & 20.87 & 0.36 & 40 & 21.92 & 0.16 \\
    \cline{2-17}
    \multicolumn{1}{|c|}{} & Iterative & 34 & 5.10 & 0.96 & 19 & 11.03 & 0.82 & 19 & 16.00 & 0.62 & 37 & 20.71 & 0.30 & 43 & 21.58 & 0.16 \\
    \hline
    \multicolumn{1}{|c|}{\multirowcell{2}{SVR}} & Direct & & & & & & & & & & & & & & & \\
    \cline{2-17}
    \multicolumn{1}{|c|}{} & Iterative & & & & & & & & & & & & & & & \\
    \hline
  \end{tabular}
\end{sidewaystable}

\end{document} 

在此处输入图片描述

答案2

这是一个使用版本booktabs,它至少遵循了部分(但不是全部)建议。这不会超出\textheight可用宽度 ()。

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{rotating,multirow,booktabs,tabularx}
\begin{document}
  \begin{sidewaystable}
    \centering
    \caption{My caption}
    \label{my-label}
    \begin{tabular}{*{17}{c}}
      \toprule
      \multirow{3}{*}{Algorithm}  & \multirow{3}{.075\textwidth}{\centering Prediction\newline Method} & \multicolumn{15}{c}{PH (min)}                                                                                                                                                                                                                                                                                                                                                                                                                                \\\cmidrule{3-17}
      & & & 10& & &20& & &30& & &45& & &60&\\ \cmidrule{3-17}
      & & W  & RMSE & $R_{adj}^2$ & W  & RMSE  & $R_{adj}^2$ & W  & RMSE  & $R_{adj}^2$ & W  & RMSE  & $R_{adj}^2$ & W  & RMSE  & Adj.\thinspace $r^2$ \\ \midrule
      Naive  &  & 49 & 7.43 & 0.90 & 49 & 13.40 & 0.69 & 49 & 17.82 & 0.45 & 49 & 21.53 & 0.16  & 49 & 22.75 & 0.00       \\\cmidrule{1-17}
      \multirow{2}{.0775\textwidth}{\centering Linear\newline Regression} & Direct & 34 & 5.10 & 0.96 & 19 & 11.03 & 0.82  & 19 & 16.08 & 0.62  & 16 & 20.87 & 0.36  & 40 & 21.92 & 0.16       \\ \cmidrule{2-17}
      & Iterative                          & 34 & 5.10 & 0.96        & 19 & 11.03 & 0.82        & 19 & 16.00 & 0.62        & 37 & 20.71 & 0.30        & 43 & 21.58 & 0.16       \\\cmidrule{1-17}
      &                                    &    &      &             &    &       &             &    &       &             &    &       &             &    &       &            \\\cmidrule{1-17}
      &                                                         &                         &                           &                                  &                         &                            &                                  &                         &                            &                                  &                         &                            &                                  &                         &                            &                                 \\\bottomrule
    \end{tabular}
  \end{sidewaystable}
\end{document}

使用 <code>booktabs</code> 进行横向表格

答案3

虽然有点晚了,但希望仍然有用。

请注意,所有\multicolumn{1}{c|}{...}包装都已消失。

在此处输入图片描述

\documentclass[a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[nomarginpar]{geometry}
\usepackage{amsmath}
\usepackage{rotating,caption,booktabs}
%% macro for a "small", i.e., compressed table
\newcommand\smtab[1]{\smash[b]{\begin{tabular}[t]{@{}l@{}}#1\end{tabular}}}

\begin{document}
\begin{sidewaystable}
\caption{My caption}
\label{my-label}
\centering
\begin{tabular}{@{} ll *{15}{c} @{}}
\toprule
Algorithm &
\smtab{Prediction\\ Method} & \multicolumn{15}{c}{PH (min)} \\ 
\cmidrule(l){3-17} 
&  & \multicolumn{3}{c}{10} 
   & \multicolumn{3}{c}{20} 
   & \multicolumn{3}{c}{30}
   & \multicolumn{3}{c}{45} 
   & \multicolumn{3}{c}{60} \\ 
\cmidrule(lr){3-5} \cmidrule(lr){6-8} \cmidrule(lr){9-11} \cmidrule(lr){12-14} \cmidrule(l){15-17}  
& & W & RMSE & $R_{\textit{adj}}^2$
  & W & RMSE & $R_{\textit{adj}}^2$ 
  & W & RMSE & $R_{\textit{adj}}^2$ 
  & W & RMSE & $R_{\textit{adj}}^2$ 
  & W & RMSE & $R_{\textit{adj}}^2$ \\
\midrule
Naive & -- & 49 & 7.43 & 0.90 & 49 & 13.40 & 0.69 & 49 & 17.82 & 0.45        & 49 & 21.53 & 0.16        & 49 & 22.75 & 0.00       \\ \addlinespace
Lin.\ Regr. & Direct                             & 34 & 5.10 & 0.96        & 19 & 11.03 & 0.82        & 19 & 16.08 & 0.62        & 16 & 20.87 & 0.36        & 40 & 21.92 & 0.16       \\ 
 & Iterative                          & 34 & 5.10 & 0.96        & 19 & 11.03 & 0.82        & 19 & 16.00 & 0.62        & 37 & 20.71 & 0.30        & 43 & 21.58 & 0.16       \\ 
\\ 
\\
\bottomrule
\end{tabular}
\end{sidewaystable}

\end{document}

相关内容