表格超出页面范围

表格超出页面范围

我知道有很多资源可以处理页面外的表格。我尝试了所有这些资源。它们要么做了一些不理想的事情,要么对我来说不起作用。请帮助我将这个表格放在我工作的中心,并使列变窄。

谢谢你! 在此处输入图片描述

\documentclass[paper=a4, fontsize=11pt]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{fourier}

\usepackage[english]{babel}                                                         % English language/hyphenation
\usepackage[protrusion=true,expansion=true]{microtype}  
\usepackage{amsmath,amsfonts,amsthm}

\usepackage{url}
\usepackage{pgfplots} %for the drawing
\usepackage{chngpage}
\usepackage{sectsty}
\allsectionsfont{\centering \normalfont\scshape}



\usepackage{fancyhdr}
\pagestyle{fancyplain}
\fancyhead{}                                            % No page header
\fancyfoot[L]{}                                         % Empty 
\fancyfoot[C]{}                                         % Empty
\fancyfoot[R]{\thepage}                                 % Pagenumbering
\renewcommand{\headrulewidth}{0pt}          % Remove header underlines
\renewcommand{\footrulewidth}{0pt}              % Remove footer underlines
\setlength{\headheight}{13.6pt}


%%% Equation and float numbering
\numberwithin{equation}{section}        % Equationnumbering: section.eq#
\numberwithin{figure}{section}          % Figurenumbering: section.fig#
\numberwithin{table}{section}               % Tablenumbering: section.tab#


%%% Maketitle metadata
\newcommand{\horrule}[1]{\rule{\linewidth}{#1}}     % Horizontal rule

\title{
        %\vspace{-1in}  
        \usefont{OT1}{bch}{b}{n}
        \normalfont \normalsize \textsc{XXX: XXX} \\ [5pt]
            \normalfont \normalsize \textsc{Dr. XXX XXX} \\ [15pt]
        \horrule{0.5pt} \\[0.4cm]
        \huge Assignment 2\\
        \horrule{2pt} \\[0.5cm]
}
\author{
        \normalfont                                 \normalsize
        XXX\\[-3pt]     \normalsize
        \today
}
\date{}


%%% Begin document
\begin{document}
\maketitle


\section*{2.24}

Refer to Copier maintenance Problem 1.20.

a. Set up the basic ANOVA table in the format of Table 2.2. Which elements of your table are additive? Also set up the ANOVA table in the format of Table 2.3. How do the two tables differ?\\\\
%%%%%%
%Attach q2.24table to the end
%%%%%%
    \textbf{Answer:} 

    First, we need to find values that will be used to construct the ANOVA table. Our initial step is taken to construct the following table (you can find the full table at the end of this homework):


 \begin{table*} \small
\caption{Data  on Copier Maintenance needed for calculation}
\centering
\begin{tabular}{c c c c c c c c c c cc}
\hline\hline
&$X_i$ & $Y_i$ & $X_i-\bar{X}$ & $Y_i-\bar{Y}$ & $\hat{Y_i}$ & $Y_i-\hat{Y_i}$& $(X_i-\bar{X})^2$&$(Y_i-\bar{Y})^2$&$(Y_i-\hat{Y_i})^2$&$\hat{Y_i}-\bar{Y}$&$(\hat{Y_i}-\bar{Y})^2$\\ [0.5ex] % inserts table %heading
\hline
&2&20&-3.11&-56.27&29.48&-9.48&9.68&3165.94&89.87&-46.79&2188.99 \\
&4&60&-1.11&-16.27&59.54&0.46&1.23&264.60&0.21&-16.73&279.78 \\
&$\cdots$ &$\cdots$&$\cdots$&$\cdots$&$\cdots$&$\cdots$&$\cdots$&$\cdots$&$\cdots$&$\cdots$&$\cdots$ \\
&4 & 61 & -1.11&-15.27&59.54&1.46 &1.23& 233.07&2.13&-16.73&279.78\\
&5 & 77 & -0.11 & 0.73&74.57&2.43&0.01&0.54&5.90&-1.70&2.88 \\ [1ex]
 \hline
 \textbf{Total}&230 &3432 & 0 & 0&3430.80&1.20&340.44&80376.8&3416.41&-1.2&76906.74 \\
  \textbf{Mean}&5.11 &76.27 &  &&& \\
\hline
\end{tabular}
\label{table:nonlin}
\end{table*}
\end{document}

答案1

一些建议:

  • 由于表格中的材料(大部分)包含数学表达式,因此我将使用环境array而不是环境tabular。通过让所有单元格自动处于数学模式,一元减号将正确排版。

  • 将控制环境\arraycolsep中列间空白量的参数设置为(或小于该值)并消除第一列左侧和最后一列右侧的空白,应该可以成功使表/数组适合文本块。array2.8pt

  • 我注意到您正在尝试改善水平线的间距。我建议不要手动进行此操作,而是使用该包的命令\toprule\midrule和。下面屏幕截图中的第二个表格显示了使用这些宏而不是(和)的结果。\bottomrulebooktabs\hline\hline\hline

在此处输入图片描述

\documentclass[paper=a4, fontsize=11pt]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{fourier}

\usepackage[english]{babel}                                                         % English language/hyphenation
\usepackage[protrusion=true,expansion=true]{microtype}  
\usepackage{amsmath,amsfonts,amsthm}

\usepackage{url}
\usepackage{pgfplots} %for the drawing
\usepackage{chngpage}
\usepackage{sectsty}
\allsectionsfont{\centering \normalfont\scshape}
\usepackage{booktabs}  %% for \toprule, \midrule, and \bottomrule


\usepackage{fancyhdr}
\pagestyle{fancyplain}
\fancyhead{}                                            % No page header
\fancyfoot[L]{}                                         % Empty 
\fancyfoot[C]{}                                         % Empty
\fancyfoot[R]{\thepage}                                 % Pagenumbering
\renewcommand{\headrulewidth}{0pt}          % Remove header underlines
\renewcommand{\footrulewidth}{0pt}              % Remove footer underlines
\setlength{\headheight}{13.6pt}


%%% Equation and float numbering
\numberwithin{equation}{section}        % Equationnumbering: section.eq#
\numberwithin{figure}{section}          % Figurenumbering: section.fig#
\numberwithin{table}{section}               % Tablenumbering: section.tab#


%%% Maketitle metadata
\newcommand{\horrule}[1]{\rule{\linewidth}{#1}}     % Horizontal rule

\title{
        %\vspace{-1in}  
        \usefont{OT1}{bch}{b}{n}
        \normalfont \normalsize \textsc{XXX: XXX} \\ [5pt]
            \normalfont \normalsize \textsc{Dr. XXX XXX} \\ [15pt]
        \horrule{0.5pt} \\[0.4cm]
        \huge Assignment 2\\
        \horrule{2pt} \\[0.5cm]
}
\author{
        \normalfont                                 \normalsize
        XXX\\[-3pt]     \normalsize
        \today
}
\date{}


%%% Begin document
\begin{document}
%\maketitle


\section*{2.24}

Refer to Copier maintenance Problem 1.20.

\noindent
a. Set up the basic ANOVA table in the format of Table 2.2. Which elements of your table are additive? Also set up the ANOVA table in the format of Table 2.3. How do the two tables differ?
%%%%%%
%Attach q2.24table to the end
%%%%%%

\noindent
\textbf{Answer:} 

\noindent
First, we need to find values that will be used to construct the ANOVA table. Our initial step is taken to construct the following table (you can find the full table at the end of this homework):


\begin{table}[h!] % location specifier just for this example
\small
\setlength\arraycolsep{2.75pt} % default value: 5pt
\caption{Data  on Copier Maintenance needed for calculation} \label{table:nonlin}

$
\begin{array}{@{}c c c c c c c c c c cc @{}}
\hline\hline
&X_i & Y_i & X_i-\bar{X} & Y_i-\bar{Y} & \hat{Y_i} & Y_i-\hat{Y_i}& (X_i-\bar{X})^2&(Y_i-\bar{Y})^2&(Y_i-\hat{Y_i})^2&\hat{Y_i}-\bar{Y}&(\hat{Y_i}-\bar{Y})^2\\ [0.5ex] % inserts table %heading
\hline
&2&20&-3.11&-56.27&29.48&-9.48&9.68&3165.94&89.87&-46.79&2188.99 \\
&4&60&-1.11&-16.27&59.54&0.46&1.23&264.60&0.21&-16.73&279.78 \\ 
& \vdots\\
&4 & 61 & -1.11&-15.27&59.54&1.46 &1.23& 233.07&2.13&-16.73&279.78\\
&5 & 77 & -0.11 & 0.73&74.57&2.43&0.01&0.54&5.90&-1.70&2.88 \\ [0.5ex]
 \hline
 \textbf{Total}&230 &3432 & 0 & 0&3430.80&1.20&340.44&80376.8&3416.41&-1.2&76906.74 \\
  \textbf{Mean}&5.11 &76.27 &  &&& \\
\hline
\end{array}$
\end{table}

\begin{table}[h!] % location specifier just for this example
\small
\setlength\arraycolsep{2.75pt} % default value: 5pt
\caption{Same table, but with lines drawn with macros of the booktabs package} \label{table:nonlin}

$
\begin{array}{@{} l *{11}{c} @{}}
\toprule
&X_i & Y_i & X_i-\bar{X} & Y_i-\bar{Y} & \hat{Y_i} & Y_i-\hat{Y_i}& (X_i-\bar{X})^2&(Y_i-\bar{Y})^2&(Y_i-\hat{Y_i})^2&\hat{Y_i}-\bar{Y}&(\hat{Y_i}-\bar{Y})^2\\ 
\midrule
&2&20&-3.11&-56.27&29.48&-9.48&9.68&3165.94&89.87&-46.79&2188.99 \\
&4&60&-1.11&-16.27&59.54&0.46&1.23&264.60&0.21&-16.73&279.78 \\
& \vdots \\
&4 & 61 & -1.11&-15.27&59.54&1.46 &1.23& 233.07&2.13&-16.73&279.78\\
&5 & 77 & -0.11 & 0.73&74.57&2.43&0.01&0.54&5.90&-1.70&2.88 \\
\midrule
 \textbf{Total}&230 &3432 & 0 & 0&3430.80&1.20&340.44&80376.8&3416.41&-1.2&76906.74 \\
  \textbf{Mean}&5.11 &76.27 &  &&& \\
\bottomrule
\end{array}$
\end{table}

\end{document}

答案2

你可以使用禁忌禁忌包裹:\usepackage{tabu}

您的表格将是一个带有\tabcolsep\extrarowsep调整的 tabu。此外,使用X[-1]创建的列的宽度刚好满足内容的需要。要将除第一列之外的所有列视为数学列,请在 tabu-preamble 中用 标记它们,并从表格主体中$删除s:$

\setlength{\tabcolsep}{2pt}
\setlength{\extrarowsep}{2pt}
\begin{tabu}{X[-1]*{11}{X[$-1]}}
\hline\hline
&X_i & Y_i & X_i-\bar{X} & Y_i-\bar{Y} & \hat{Y_i} & Y_i-\hat{Y_i}& (X_i-\bar{X})^2&(Y_i-\bar{Y})^2&(Y_i-\hat{Y_i})^2&\hat{Y_i}-\bar{Y}&(\hat{Y_i}-\bar{Y})^2\\ [0.5ex] % inserts table %heading
\hline
&2&20&-3.11&-56.27&29.48&-9.48&9.68&3165.94&89.87&-46.79&2188.99 \\
&4&60&-1.11&-16.27&59.54&0.46&1.23&264.60&0.21&-16.73&279.78 \\
&\cdots &\cdots&\cdots&\cdots&\cdots&\cdots&\cdots&\cdots&\cdots&\cdots&\cdots \\
&4 & 61 & -1.11&-15.27&59.54&1.46 &1.23& 233.07&2.13&-16.73&279.78\\
&5 & 77 & -0.11 & 0.73&74.57&2.43&0.01&0.54&5.90&-1.70&2.88 \\ [1ex]
 \hline
 \textbf{Total}&230 &3432 & 0 & 0&3430.80&1.20&340.44&80376.8&3416.41&-1.2&76906.74 \\
  \textbf{Mean}&5.11 &76.27 &  &&& \\
\hline
\end{tabu}

禁忌

相关内容