表格和长表格式

表格和长表格式

在此处输入图片描述

我已经为所展示的表格编写了 LaTeX 代码,但输出结果超出了页面范围,看起来不太一样。我的意思是单元格值分散了。每个单元格中的数字都上下排列。我的代码中存在什么问题?如何控制单元格宽度?

我可以将代码转换成长表格式吗?

\documentclass[12pt,a4paper]{article}
\begin{document}
\begin{table}
    \begin{tabular}{|l|l|l|l|l|l|l|l|l|l|l|l|lll}
    ~    & ~                                & ~                              & ~                                       & ~                              & ~                              & ~                              & ~                                & ~                                & ~                                 & ~                                       & ~                                 & ~                              & ~                                       & ~                              \\ \hline
    ~    & Full                             & 2000                           & 2001                                    & 2002                           & 2003                           & 2004                           & 2005                             & 2006                             & 2007                              & 2008                                    & 2009                              & 2010                           & 2011                                    & 2012                           \\ \hline
    Low  &  Consumer Staples\\ 15.83\%      &  Utilities 14.50\%             &  Consumer Staples 16.70\%               &  Consumer Staples 21.20\%      &  Consumer Staples\\ 17.49\%    &  Consumer Staples 10.04\%      &             Consumer            Staples             8.73\% &            Consumer            Staples             9.66\% &  Healthcare 12.58\%               &            Consumer            Staples             28.83\%      &  Healthcare 16.10\%               &  Healthcare 13.59\%            &  Consumer Staples 14.21\%               &  Consumer Staples 11.12\%      \\ \hline
    2    &  Healthcare\\ 17.70\%            &  Consumer Staples\\ 15.92\%    &  Utilities 16.81\%                      &  Utilities 22.49\%             &           Utilities           18.67\%       &  Utilities 10.70\%             &  Financials 10.25\%              &  Healthcare 11.46\%              &              Consumer            Staples             12.77\% &  Healthcare 28.84\%                     &             Consumer            Staples             16.64\% &  Consumer Staples 14.53\%      &  Healthcare 15.89\%                     &  Healthcare 11.28\%            \\ \hline
    3    &              Utilities\\             19.48\%       &  Materials 15.97\%             &  Materials 19.12\%                      &  Materials 24.66\%             &  Industrials 20.74\%           &  Healthcare 12.64\%            &  Consumer Discretionary 10.51\%  &  Utilities 13.34\%               &  Utilities 13.66\%                &  Telecom 35.05\%                        &  Telecom 20.70\%                  &  Telecom 17.02\%               &  Telecom 19.31\%                        &  Telecom 13.98\%               \\ \hline
    4    &  Industrials\\ 23.36\%           &  Financials 17.23\%            &  Healthcare 20.95\%                     &  Industrials 25.87\%           &  Healthcare 21.83\%            &  Financials 12.94\%            &  Industrials 10.78\%             &  Consumer Discretionary 13.66\%  &  Consumer Discretionary 17.31\%   &  Utilities 39.31\%                      &  Utilities 22.22\%                &  Utilities 17.17\%             &  Utilities 23.33\%                      &  Utilities 15.96\%             \\ \hline
    5    &  Consumer Discretionary\\ 24.04\% &  Industrials 17.69\%           &  Industrials 22.17\%                    &  Healthcare 26.78\%            &  Materials 22.13\%             &  Industrials 13.39\%           &  Healthcare 10.79\%              &  Financials 14.59\%              &  Telecom 17.74\%                  &  Consumer Discretionary 42.57\%         &  Consumer Discretionary 26.25\%   &  Information Technology 19.66\% &  Energy 23.96\%                         &  Energy 16.62\%                \\ \hline
    6    &  Energy\\ 24.87\%                &  Healthcare 18.97\%            &  Energy 27.71\%                         &  Consumer Discretionary 32.04\% &  Energy\\ 22.85\%              &  Materials 13.44\%             &  Utilities 11.71\%               &  Telecom 15.40\%                 &  Energy 18.37\%                   &              Information             Technology          42.94\% &           Energy          27.60\%             &  Energy 19.78\%                &              Consumer            Discretionary           26.55\% &  Industrials 18.50\%           \\ \hline
    7    &  Telecom\\ 25.50\%               &  Consumer Discretionary 23.06\% &  Consumer Discretionary 28.20\%         &  Energy 32.63\%                &  Telecom 23.01\%               &  Consumer Discretionary 14.31\% &  Telecom 11.88\%                 &  Industrials 16.47\%             &  Financials 19.46\%               &  Industrials 43.58\%                    &  Information Technology 29.74\%   &  Consumer Discretionary 21.12\% &  Information Technology 26.91\%         &  Consumer Discretionary 18.52\% \\ \hline
    8    &  Materials\\ 26.92\%             &  Energy\\ 26.09\%              &  Financials 28.02\%                     &  Financials 36.18\%            &  Consumer Discretionary 24.72\% &  Energy 14.86\%                &  Materials 12.69\%               &  Energy 16.48\%                  &  Industrials 19.96\%              &  Energy 46.89\%                         &  Industrials 30.94\%              &            Industrials             21.95\%     &  Industrials 27.78\%                    &  Information Technology 19.30\% \\ \hline
    9    &  Financials\\ 28.33\%            &  Telecom 42.68\%               &  Telecom 37.31\%                        &  Telecom 39.65\%               &  Financials 26.17\%            &  Telecom 14.87\%               &  Information Technology 15.49\%  &  Information Technology 19.03\%  &  Information Technology 20.43\%   &  Financials 50.61\%                     &  Materials 41.26\%                &  Materials 26.86\%             &  Materials 30.38\%                      &  Materials 21.68\%             \\ \hline
    High &  Information Technology\\ 34.91\% &  Information Technology 52.46\% &            Information             Technology          58.59\% &  Information Technology 53.73\% &  Information Technology 37.15\% &  Information Technology 26.39\% &  Energy 16.23\%                  &  Materials 19.45\%               &  Materials 23.87\%                &  Materials 53.86\%                      &  cc                               &  Financials 43.69\%            &  Financials 27.01\%                     &  Financials 33.02\%            \\ \hline
    \end{tabular}
\end{table}
\end{document}

编辑:

     \documentclass[12pt,a4paper]{article}
\usepackage{amsmath}\usepackage{amssymb}\usepackage{tabularx} \usepackage{comment}
\oddsidemargin-16mm
\usepackage{graphicx} \usepackage{hyperref} \usepackage[english]{babel}
\usepackage{lscape}
\usepackage{rotating}
\newcommand{\specificthanks}[1]{\@fnsymbol{#1}}% Inserts a specific \thanks symbol
\usepackage[left=1.25in, right=1.0in, top=1.25in, bottom=1.0in]{geometry}
\usepackage{booktabs} % Allows the use of \toprule, \midrule and \bottomrule in tables for horizontal lines
\newcommand{\piRsquare}{\pi r^2}
\begin{document} \baselineskip=22pt
\begin{landscape}
\maketitle
%\begin{table}
%    \begin{tabular}{|l|l|l|l|l|l|l|l|l|l|l|l|lll}
  \begin{tabular}{|*{15}{p{7mm}|}}
    ~    & ~                                & ~                              & ~                                       & ~                              & ~                              & ~                              & ~                                & ~                                & ~                                 & ~                                       & ~                                 & ~                              & ~                                       & ~                              \\ \hline
    ~    & Full                             & 2000                           & 2001                                    & 2002                           & 2003                           & 2004                           & 2005                             & 2006                             & 2007                              & 2008                                    & 2009                              & 2010                           & 2011                                    & 2012                           \\ \hline
    Low  &  Consu\-mer Staples  15.83\%      &  Utili\-ties 14.50\%             &  Consu\-mer Staples 16.70\%               &  Consu\-mer Staples 21.20\%      &  Consu\-mer Staples 17.49\%    &  Consu\-mer Staples 10.04\%      &             Consu\-mer            Staples             8.73\% &            Consu\-mer            Staples             9.66\% &  Health\-care 12.58\%               &            Consu\-mer            Staples             28.83\%      &  Health\-care 16.10\%               &  Health\-care 13.59\%            &  Consu\-mer Staples 14.21\%               &  Consu\-mer Staples 11.12\%      \\ \hline
\end{tabular} % prematurely
\begin{comment}
    2    &  Healthcare\\ 17.70\%            &  Consumer Staples\\ 15.92\%    &  Utilities 16.81\%                      &  Utilities 22.49\%             &           Utilities           18.67\%       &  Utilities 10.70\%             &  Financials 10.25\%              &  Healthcare 11.46\%              &              Consumer            Staples             12.77\% &  Healthcare 28.84\%                     &             Consumer            Staples             16.64\% &  Consumer Staples 14.53\%      &  Healthcare 15.89\%                     &  Healthcare 11.28\%            \\ \hline
    3    &              Utilities\\             19.48\%       &  Materials 15.97\%             &  Materials 19.12\%                      &  Materials 24.66\%             &  Industrials 20.74\%           &  Healthcare 12.64\%            &  Consumer Discretionary 10.51\%  &  Utilities 13.34\%               &  Utilities 13.66\%                &  Telecom 35.05\%                        &  Telecom 20.70\%                  &  Telecom 17.02\%               &  Telecom 19.31\%                        &  Telecom 13.98\%               \\ \hline
    4    &  Industrials\\ 23.36\%           &  Financials 17.23\%            &  Healthcare 20.95\%                     &  Industrials 25.87\%           &  Healthcare 21.83\%            &  Financials 12.94\%            &  Industrials 10.78\%             &  Consumer Discretionary 13.66\%  &  Consumer Discretionary 17.31\%   &  Utilities 39.31\%                      &  Utilities 22.22\%                &  Utilities 17.17\%             &  Utilities 23.33\%                      &  Utilities 15.96\%             \\ \hline
    5    &  Consumer Discretionary\\ 24.04\% &  Industrials 17.69\%           &  Industrials 22.17\%                    &  Healthcare 26.78\%            &  Materials 22.13\%             &  Industrials 13.39\%           &  Healthcare 10.79\%              &  Financials 14.59\%              &  Telecom 17.74\%                  &  Consumer Discretionary 42.57\%         &  Consumer Discretionary 26.25\%   &  Information Technology 19.66\% &  Energy 23.96\%                         &  Energy 16.62\%                \\ \hline
    6    &  Energy\\ 24.87\%                &  Healthcare 18.97\%            &  Energy 27.71\%                         &  Consumer Discretionary 32.04\% &  Energy\\ 22.85\%              &  Materials 13.44\%             &  Utilities 11.71\%               &  Telecom 15.40\%                 &  Energy 18.37\%                   &              Information             Technology          42.94\% &           Energy          27.60\%             &  Energy 19.78\%                &              Consumer            Discretionary           26.55\% &  Industrials 18.50\%           \\ \hline
    7    &  Telecom\\ 25.50\%               &  Consumer Discretionary 23.06\% &  Consumer Discretionary 28.20\%         &  Energy 32.63\%                &  Telecom 23.01\%               &  Consumer Discretionary 14.31\% &  Telecom 11.88\%                 &  Industrials 16.47\%             &  Financials 19.46\%               &  Industrials 43.58\%                    &  Information Technology 29.74\%   &  Consumer Discretionary 21.12\% &  Information Technology 26.91\%         &  Consumer Discretionary 18.52\% \\ \hline
    8    &  Materials\\ 26.92\%             &  Energy\\ 26.09\%              &  Financials 28.02\%                     &  Financials 36.18\%            &  Consumer Discretionary 24.72\% &  Energy 14.86\%                &  Materials 12.69\%               &  Energy 16.48\%                  &  Industrials 19.96\%              &  Energy 46.89\%                         &  Industrials 30.94\%              &            Industrials             21.95\%     &  Industrials 27.78\%                    &  Information Technology 19.30\% \\ \hline
    9    &  Financials\\ 28.33\%            &  Telecom 42.68\%               &  Telecom 37.31\%                        &  Telecom 39.65\%               &  Financials 26.17\%            &  Telecom 14.87\%               &  Information Technology 15.49\%  &  Information Technology 19.03\%  &  Information Technology 20.43\%   &  Financials 50.61\%                     &  Materials 41.26\%                &  Materials 26.86\%             &  Materials 30.38\%                      &  Materials 21.68\%             \\ \hline
    High &  Information Technology\\ 34.91\% &  Information Technology 52.46\% &            Information             Technology          58.59\% &  Information Technology 53.73\% &  Information Technology 37.15\% &  Information Technology 26.39\% &  Energy 16.23\%                  &  Materials 19.45\%               &  Materials 23.87\%                &  Materials 53.86\%                      &  cc                               &  Financials 43.69\%            &  Financials 27.01\%                     &  Financials 33.02\%            \\ \hline
    \end{tabular}
\end{table}
\end{comment}

\end{landscape}
%

\end{document}

答案1

如何通过转置操作切换表格内容并将其置于横向模式。这里,tabularx使用包中的 X 列,选项 width=1.2\textwidth允许将表格向右扩展,以便根据需要提高可读性。

在此处输入图片描述

代码

\documentclass{article}
\usepackage{tabularx}
\usepackage{pdflscape}
\usepackage[margin=10pt]{geometry}

\begin{document}
\begin{landscape}
\begin{tabularx}{1.2\textwidth}{|l|*{10}{X|}}\hline
& Low & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & High \\ \hline
Fall & Consumer Staples 15.83\% &Healthcare 17.70\%  & Utilities 19.48\%  &   Industrials 23.36\%  & Consumer Discretionary 24.04\% & Energy 24.87\%   & Telecom 25.50\% &  Materials 26.92\%  & Financials 28.33\%  &Information Technology 34.91\% \\ \hline
2000 & Utilities 14.50\%         & Consumer Staples 15.92\%  & & & & & & &  &\\\hline
2001 & Consumer Staples 16.70\%  & Utilities 16.81\%   &  & & & & & &  &\\\hline
2002 & Consumer Staples 21.20\%  & Utilities 22.49\%   &  & & & & & & & \\\hline
2031 & Consumer Staples 17.49\%  & Utilities 18.67\%   &  & & & & & & & \\\hline
2004 & Consumer Staples 10.04\%  & Utilities 10.70\%   &  & & & & & &  & \\\hline
2005 & Consumer Staples 8.73\%   & Financials 10.25\%  &  & & & & & &  & \\\hline
2006 & Consumer Staples 9.66\%   & Healthcare 11.46\%  & & & & & & &  & \\\hline
2007 & Healthcare 12.58\%        & Consumer Staples 12.77\% & & & & & & & & \\\hline
2008 & Consumer Staples  28.83\% & Healthcare 28.84\%  & & & & & & & & \\\hline
2009 & Healthcare 16.10\%        & Consumer Staples 16.64\% & & & & & & & &\\\hline
2010 & Healthcare 13.59\%        & Consumer Staples 14.53\% & & & & & & & & \\\hline
2011 & Consumer  Staples 14.21\% & Healthcare 15.89\%  &   & & & & & & & \\\hline
2012 & Consumer Staples 11.12\%  & Healthcare 11.28\%  & & & & & & & &  \\\hline
\end{tabularx} 
\end{landscape}        
\end{document}

答案2

编辑:这部分是对问题初始版本的回答,因此一些片段纠正了旧版本。

您可以使用 byp{with}选项来控制单元格。但是对于如此大量的数据,您应该会遇到很多问题。一个逻辑行被更正了(\\在这种情况下不是)。您的大多数代码都带有注释,以显示发生了什么。

%\documentclass[12pt,a4paper]{article}
\documentclass{article}

\usepackage{comment}

\oddsidemargin-16mm
\begin{document}

\tiny

%\begin{table}
%    \begin{tabular}{|l|l|l|l|l|l|l|l|l|l|l|l|lll}
  \begin{tabular}{|*{15}{p{7mm}|}}
    ~    & ~                                & ~                              & ~                                       & ~                              & ~                              & ~                              & ~                                & ~                                & ~                                 & ~                                       & ~                                 & ~                              & ~                                       & ~                              \\ \hline
    ~    & Full                             & 2000                           & 2001                                    & 2002                           & 2003                           & 2004                           & 2005                             & 2006                             & 2007                              & 2008                                    & 2009                              & 2010                           & 2011                                    & 2012                           \\ \hline
    Low  &  Consu\-mer Staples  15.83\%      &  Utili\-ties 14.50\%             &  Consu\-mer Staples 16.70\%               &  Consu\-mer Staples 21.20\%      &  Consu\-mer Staples 17.49\%    &  Consu\-mer Staples 10.04\%      &             Consu\-mer            Staples             8.73\% &            Consu\-mer            Staples             9.66\% &  Health\-care 12.58\%               &            Consu\-mer            Staples             28.83\%      &  Health\-care 16.10\%               &  Health\-care 13.59\%            &  Consu\-mer Staples 14.21\%               &  Consu\-mer Staples 11.12\%      \\ \hline
\end{tabular} % prematurely
\begin{comment}
    2    &  Healthcare\\ 17.70\%            &  Consumer Staples\\ 15.92\%    &  Utilities 16.81\%                      &  Utilities 22.49\%             &           Utilities           18.67\%       &  Utilities 10.70\%             &  Financials 10.25\%              &  Healthcare 11.46\%              &              Consumer            Staples             12.77\% &  Healthcare 28.84\%                     &             Consumer            Staples             16.64\% &  Consumer Staples 14.53\%      &  Healthcare 15.89\%                     &  Healthcare 11.28\%            \\ \hline
    3    &              Utilities\\             19.48\%       &  Materials 15.97\%             &  Materials 19.12\%                      &  Materials 24.66\%             &  Industrials 20.74\%           &  Healthcare 12.64\%            &  Consumer Discretionary 10.51\%  &  Utilities 13.34\%               &  Utilities 13.66\%                &  Telecom 35.05\%                        &  Telecom 20.70\%                  &  Telecom 17.02\%               &  Telecom 19.31\%                        &  Telecom 13.98\%               \\ \hline
    4    &  Industrials\\ 23.36\%           &  Financials 17.23\%            &  Healthcare 20.95\%                     &  Industrials 25.87\%           &  Healthcare 21.83\%            &  Financials 12.94\%            &  Industrials 10.78\%             &  Consumer Discretionary 13.66\%  &  Consumer Discretionary 17.31\%   &  Utilities 39.31\%                      &  Utilities 22.22\%                &  Utilities 17.17\%             &  Utilities 23.33\%                      &  Utilities 15.96\%             \\ \hline
    5    &  Consumer Discretionary\\ 24.04\% &  Industrials 17.69\%           &  Industrials 22.17\%                    &  Healthcare 26.78\%            &  Materials 22.13\%             &  Industrials 13.39\%           &  Healthcare 10.79\%              &  Financials 14.59\%              &  Telecom 17.74\%                  &  Consumer Discretionary 42.57\%         &  Consumer Discretionary 26.25\%   &  Information Technology 19.66\% &  Energy 23.96\%                         &  Energy 16.62\%                \\ \hline
    6    &  Energy\\ 24.87\%                &  Healthcare 18.97\%            &  Energy 27.71\%                         &  Consumer Discretionary 32.04\% &  Energy\\ 22.85\%              &  Materials 13.44\%             &  Utilities 11.71\%               &  Telecom 15.40\%                 &  Energy 18.37\%                   &              Information             Technology          42.94\% &           Energy          27.60\%             &  Energy 19.78\%                &              Consumer            Discretionary           26.55\% &  Industrials 18.50\%           \\ \hline
    7    &  Telecom\\ 25.50\%               &  Consumer Discretionary 23.06\% &  Consumer Discretionary 28.20\%         &  Energy 32.63\%                &  Telecom 23.01\%               &  Consumer Discretionary 14.31\% &  Telecom 11.88\%                 &  Industrials 16.47\%             &  Financials 19.46\%               &  Industrials 43.58\%                    &  Information Technology 29.74\%   &  Consumer Discretionary 21.12\% &  Information Technology 26.91\%         &  Consumer Discretionary 18.52\% \\ \hline
    8    &  Materials\\ 26.92\%             &  Energy\\ 26.09\%              &  Financials 28.02\%                     &  Financials 36.18\%            &  Consumer Discretionary 24.72\% &  Energy 14.86\%                &  Materials 12.69\%               &  Energy 16.48\%                  &  Industrials 19.96\%              &  Energy 46.89\%                         &  Industrials 30.94\%              &            Industrials             21.95\%     &  Industrials 27.78\%                    &  Information Technology 19.30\% \\ \hline
    9    &  Financials\\ 28.33\%            &  Telecom 42.68\%               &  Telecom 37.31\%                        &  Telecom 39.65\%               &  Financials 26.17\%            &  Telecom 14.87\%               &  Information Technology 15.49\%  &  Information Technology 19.03\%  &  Information Technology 20.43\%   &  Financials 50.61\%                     &  Materials 41.26\%                &  Materials 26.86\%             &  Materials 30.38\%                      &  Materials 21.68\%             \\ \hline
    High &  Information Technology\\ 34.91\% &  Information Technology 52.46\% &            Information             Technology          58.59\% &  Information Technology 53.73\% &  Information Technology 37.15\% &  Information Technology 26.39\% &  Energy 16.23\%                  &  Materials 19.45\%               &  Materials 23.87\%                &  Materials 53.86\%                      &  cc                               &  Financials 43.69\%            &  Financials 27.01\%                     &  Financials 33.02\%            \\ \hline
    \end{tabular}
\end{table}
\end{comment}

\end{document}

在此处输入图片描述

这是文档\tiny中的!10pt

转换为风景模式的描述如下:如何将某些页面更改为横向/纵向模式

但是,如果您可以稍微修改一下代码,以下解决方案会将您的表格拆分为两部分(仅拆分前 3 行)。请注意& -> &!使用时第 8 列末尾的转换\2

\def\1 #1& #2 & #3 & #4 & #5 & #6 & #7 & #8 & #9 \\ \hline{ #1& #2 & #3 & #4 & #5 & #6 & #7 & #8 \\ \hline}
%  \begin{tabular}{|*{15}{p{7mm}|}}
 \begin{tabular}{|*{8}{p{7mm}|}}
\1    ~    & ~                                & ~                              & ~                                       & ~                              & ~                              & ~                              & ~                                & ~                                & ~                                 & ~                                       & ~                                 & ~                              & ~                                       & ~                              \\ \hline
\1    ~    & Full                             & 2000                           & 2001                                    & 2002                           & 2003                           & 2004                           & 2005                             & 2006                             & 2007                              & 2008                                    & 2009                              & 2010                           & 2011                                    & 2012                           \\ \hline
\1    Low  &  Consu\-mer Staples  15.83\%      &  Utili\-ties 14.50\%             &  Consu\-mer Staples 16.70\%               &  Consu\-mer Staples 21.20\%      &  Consu\-mer Staples 17.49\%    &  Consu\-mer Staples 10.04\%      &             Consu\-mer            Staples             8.73\% &            Consu\-mer            Staples             9.66\% &  Health\-care 12.58\%               &            Consu\-mer            Staples             28.83\%      &  Health\-care 16.10\%               &  Health\-care 13.59\%            &  Consu\-mer Staples 14.21\%               &  Consu\-mer Staples 11.12\%      \\ \hline
\end{tabular} 

\bigskip

\def\2 #1&! #2 & #3 & #4 & #5 & #6 & #7 & #8 \\ \hline{  #2 & #3 & #4 & #5 & #6 & #7 & #8 \\ \hline}
%  \begin{tabular}{|*{15}{p{7mm}|}}
 \begin{tabular}{|*{8}{p{7mm}|}}
\2    ~    & ~                                & ~                              & ~                                       & ~                              & ~                              & ~                              & ~                                &! ~                                & ~                                 & ~                                       & ~                                 & ~                              & ~                                       & ~                              \\ \hline
\2    ~    & Full                             & 2000                           & 2001                                    & 2002                           & 2003                           & 2004                           & 2005                             & !2006                             & 2007                              & 2008                                    & 2009                              & 2010                           & 2011                                    & 2012                           \\ \hline
\2   Low  &  Consu\-mer Staples  15.83\%      &  Utili\-ties 14.50\%             &  Consu\-mer Staples 16.70\%               &  Consu\-mer Staples 21.20\%      &  Consu\-mer Staples 17.49\%    &  Consu\-mer Staples 10.04\%      &             Consu\-mer            Staples             8.73\% &!            Consu\-mer            Staples             9.66\% &  Health\-care 12.58\%               &            Consu\-mer            Staples             28.83\%      &  Health\-care 16.10\%               &  Health\-care 13.59\%            &  Consu\-mer Staples 14.21\%               &  Consu\-mer Staples 11.12\%      \\ \hline
\end{tabular}

在此处输入图片描述

如果您不怕重复表格的代码,这些复杂的定义可以转换为只有 2 个形式参数的定义;但是这个想法是在您需要将表格分成 3 个部分的情况下提出的。

相关内容