大型横向表格,带自动换行功能

大型横向表格,带自动换行功能

我需要在作品的附录中插入一个大表格。我正在使用此网站生成的代码(https://www.latex-tables.com/):

\begin{sidewaystable}
\centering
\arrayrulecolor{black}
\resizebox{\linewidth}{!}{%
\begin{tabular}{!{\color[rgb]{0.749,0.749,0.749}\vrule}l!{\color{black}\vrule}l!{\color[rgb]{0.749,0.749,0.749}\vrule}l!{\color[rgb]{0.749,0.749,0.749}\vrule}l!{\color[rgb]{0.749,0.749,0.749}\vrule}l!{\color[rgb]{0.749,0.749,0.749}\vrule}l!{\color[rgb]{0.749,0.749,0.749}\vrule}} 
\hline
\multicolumn{6}{!{\color[rgb]{0.749,0.749,0.749}\vrule}l!{\color{black}\vrule}}{Pre-Fornero period (2012)}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            \\ 
\hline
\rowcolor[rgb]{0.949,0.949,0.949} ~                        & Indennità di disoccupazione ordinaria (IDO)                                                                                                   & Indennità di disoccupazione a requisiti ridotti (IDRR)                                                                           & Indennità di disoccupazione agricola (IDA)                & Indennità di disoccupazione edile (IDE)                                                                                                                                              & Indennità di mobilità ordinaria (IMO)                                                                                                                              \\ 
\hline
Firms~ and sectors                                         & All firms, all sectors                                                                                                                        & All firms, all sectors                                                                                                           & All firms, agricoltural sector                            & All firms, construction sector et similia                                                                                                                                            & Firms with more than 15 employees, industrial sector (but not the construction sector), commercial sector (firm with more than 50 employees), other minor sectors  \\ 
\hline
\rowcolor[rgb]{0.949,0.949,0.949} Workers                  & Unemployed, formerly dependent workers                                                                                                        & Dependent workers                                                                                                                & Dependent workers                                         & Unemployed, formerly dependent workers                                                                                                                                               & Unemployed workers fired in a collective firing, formerly open end dependent workers; alternatively, workers benefiting from CIGS (after its expiration)           \\ 
\hline
Insurance requirement                                      & 2 years                                                                                                                                       & 2 years                                                                                                                          & 2 years                                                   & /                                                                                                                                                                                    & /                                                                                                                                                                  \\ 
\hline
\rowcolor[rgb]{0.949,0.949,0.949} Contribution requirement & 52 weeks in the previous 2 years                                                                                                              & 78 days in the previous 12 months                                                                                                & 102 days in the previous 12 months                        & 10 months or 43 weeks~                                                                                                                                                               & 12 months of seniority in the firm                                                                                                                                 \\ 
\hline
Duration                                                   & \begin{tabular}[c]{@{}l@{}}- Age \textless{} 50: 8 months\\~- Age \textgreater{} 50: 12 months\end{tabular}                                   & Settled in a single payment                                                                                                      & = number of days of contribution                          & 90 days                                                                                                                                                                              & \begin{tabular}[c]{@{}l@{}}- Age \textless{} 40: 12 months\\~- Age 40-50: 24 months\\~- Age \textgreater{} 50: 36 months\end{tabular}                              \\ 
\hline
\rowcolor[rgb]{0.949,0.949,0.949} Replacement rate         & \begin{tabular}[c]{@{}>{\cellcolor[rgb]{0.949,0.949,0.949}}l@{}}- First 6 months: 60\%\\~- Second 6 months: 50\%\\~- After: 40\%\end{tabular} & \begin{tabular}[c]{@{}>{\cellcolor[rgb]{0.949,0.949,0.949}}l@{}}- First 4 months: 35\%\\~- Following 2 months: 40\%\end{tabular} & 40\%                                                      & 80\%                                                                                                                                                                                 & \begin{tabular}[c]{@{}>{\cellcolor[rgb]{0.949,0.949,0.949}}l@{}}- First 12 months: 80\%\\~- After: 64\%\end{tabular}                                               \\ 
\hline
Other comments                                             & No access for apprentices and other para-subordinated (a part from experimentatios)                                                           & No proof of unemployment required                                                                                                & An IDA requisiti ridotti and an IDA speciale existed too. & Workers fired because of: cessation of business, end of a construction, reduction of personnel, serious company crisis. Also dimission for just cause. An IDE speciale existed too.~ & Duration increased by 12 months in southern regions. An IMO lunga, anticipate and in deroga existed.                                                               \\
\hline
\end{tabular}
}
\arrayrulecolor{black}
\end{sidewaystable}

我遇到了非自动换行的常见问题。我知道我需要的命令是,\tabularx但我不明白如何让 tabularx 在网站生成的代码中工作。

在此处输入图片描述

答案1

我想我们都同意 latex-tables.com 上的工具产生的结果是不可读的:

在此处输入图片描述

至少,这幅图非常生动地说明了为什么使用\resizebox{\linewidth}{...}“包装器”方法往往无法产生可接受的结果。

那么,如果我们的目标是避免输出结果小到难以辨认,该怎么办呢?以下是一些建议:

  • 使用tabularx环境并允许所有 6 列自动换行
  • 通过省略所有垂直线和大部分水平线来简化和精简表格的“外观”。
  • 在窄列中使用右对齐排版。

在此处输入图片描述

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[margin=2.5cm]{geometry} % set page parameters suitably
\usepackage{rotating,tabularx,ragged2e,booktabs,caption}
\newcolumntype{L}[2]{>{\RaggedRight\arraybackslash%
        \hsize=#1\hsize\linewidth=\hsize}X}
\newcolumntype{P}[2]{>{\RaggedRight}p{#1}}
\newlength\mylen
\settowidth{\mylen}{Insurance requirement} % measure desired width of first column

\begin{document}
\begin{sidewaystable}
\setlength\tabcolsep{3pt}
\caption*{Pre-Fornero period (2012)}
\begin{tabularx}{\textwidth}{@{} 
    P{\mylen} 
    *{2}{L{1}}
    L{0.9} 
    *{2}{L{1.05}} % sum of rel. column widths = # of columns of type 'L'
    @{}}
\toprule
& Indennità di disoccupazione ordinaria (IDO)
& Indennità di disoccupazione a requisiti ridotti (IDRR)
& Indennità di disoccupazione agricola (IDA)
& Indennità di disoccupazione edile (IDE)
& Indennità di mobilità ordinaria (IMO) \\
\midrule
Firms and sectors
& All firms, all sector
& All firms, all sectors
& All firms, agricultural sector
& All firms, construction sector and similar
& Firms with more than 15 employees, industrial sector 
  (but not the construction sector), commercial sector 
  (firm with more than 50 employees), other minor sectors  \\
\addlinespace
Workers
& Unemployed, formerly dependent workers
& Dependent workers
& Dependent workers
& Unemployed, formerly dependent workers
& Unemployed workers fired in a collective firing,
  formerly open end dependent workers; alternatively,
  workers benefiting from CIGS (after its expiration) \\
\addlinespace
Insurance requirement
& 2 years & 2 years & 2 years & -- & -- \\
\addlinespace
Contribution requirement
& 52 weeks in the previous 2 years
& 78 days in the previous 12 months
& 102 days in the previous 12 months
& 10 months or 43 weeks
& 12 months of seniority in the firm \\
\addlinespace
Duration
& \begin{tabular}[t]{@{}l@{}}
    - Age<50: 8 months\\
    - Age>50: 12 months
  \end{tabular}
& Settled in a single payment
& = number of days of contribution
& 90 days
& \begin{tabular}[t]{@{}l@{}}
    - Age<40: 12 months\\
    - Age 40--50: 24 months\\
    - Age>50: 36 months
  \end{tabular} \\
\addlinespace
Replacement rate
& \begin{tabular}[t]{@{}>{}l@{}}
    - First 6 months: 60\%\\
    - Second 6 months: 50\%\\
    - After: 40\%
  \end{tabular}
& \begin{tabular}[t]{@{}>{}l@{}}
    - First 4 months: 35\%\\
    - Foll.\ 2 months: 40\%
  \end{tabular}
& 40\% & 80\%
& \begin{tabular}[t]{@{}>{}l@{}}
    - First 12 months: 80\%\\
    - After: 64\%
  \end{tabular} \\
\addlinespace
Other comments
& No access for apprentices and other para-subordinated
  (a part from experimentatios)
& No proof of unemployment required
& An IDA requisiti ridotti and an IDA speciale existed too.
& Workers fired because of: cessation of business, end of a
  construction, reduction of personnel, serious company crisis.
  Also dismissal for just cause. An IDE speciale existed too.
& Duration increased by 12 months in southern regions. An
  IMO lunga, anticipate and in deroga existed. \\
\bottomrule
\end{tabularx}
\end{sidewaystable}

\end{document}

答案2

我建议另一种布局,也基于 tabularx,带有一些颜色,并用自定义itemize环境替换嵌套的表格:

\documentclass{article}
\usepackage{geometry}
\usepackage{ragged2e}
\usepackage{lscape}
\usepackage{rotating, graphicx, adjustbox}
\usepackage{tabularx}
\usepackage[table, svgnames]{xcolor}
\definecolor{vcolor}{rgb}{0.749,0.749,0.749}
\definecolor{rcolor}{rgb}{0.949,0.949,0.949}
\usepackage{enumitem}
\usepackage{setspace}

\begin{document}

\begin{sidewaystable}
\setlist[itemize]{wide=0pt, label=--, leftmargin=*, nosep, before=\leavevmode\vspace*{-\baselineskip}, after = \vspace*{-2.5ex}}%
\renewcommand{\tabularxcolumn}[1]{>{\small\RaggedRight}p{#1}}
\setstretch{0.9}
\centering\setlength{\tabcolsep}{3pt}\setlength{\extrarowheight}{2pt}%
\rowcolors{4}{}{rcolor}
 \begin{tabularx}{\textheight}%
 {|*{3}{p{32mm}!{\color{vcolor}\vrule}}X !{\color{vcolor}\vrule}X|}
%\hline
\multicolumn{5}{c}{Pre-Fornero period (2012)} \\
\hline
\rowcolor{Silver!40!Lavender}\multicolumn{5}{|c|}{Indennità di disoccupazione} \\[-1pt]
\rowcolor{Silver!40!Lavender}ordinaria (IDO) & a requisiti ridotti (IDRR) & agricola (IDA) & edile (IDE) & Indennità di mobilità ordinaria (IMO) \\
\hline
 \multicolumn{5}{|l|}{Firms and sectors} \\
Firms and sectors\newline All firms, all sectors & All firms, all sectors & All firms, agricoltural sector & All firms, construction sector et similia & Firms with more than 15 employees, industrial sector (but not the construction sector), commercial sector (firm with more than 50 employees), other minor sectors \\
 \multicolumn{5}{|l}{Workers} \\
  Unemployed, formerly dependent workers & Dependent workers & Dependent workers & Unemployed, formerly dependent workers & Unemployed workers fired in a collective firing, formerly open end dependent workers; alternatively, workers benefiting from CIGS (after its expiration) \\
\multicolumn{5}{|l|}{Insurance requirement} \\ 2 years & 2 years & 2 years & / & / \\
\multicolumn{5}{|l|}{ Contribution requirement} \\
 52 weeks in the previous 2 years & 78 days in the previous 12 months & 102 days in the previous 12 months & 10 months or 43 weeks~ & 12 months of seniority in the firm \\
 \multicolumn{5}{|l|}{Duration} \\
 \begin{itemize}\item Age ${} < 50 : 8$ months \item Age \textgreater{} 50: 12 months\end{itemize} & Settled in a single payment & = number of days of contribution & 90 days & \begin{itemize}\item Age $ < 40: $ 12 months \item Age $40\mbox{--}50:$ 24 months \item Age $ > 50: $ 36 months\end{itemize} \\
  \multicolumn{5}{|l|}{Replacement rate} \\
 \begin{itemize}\item First 6 months: 60\,\% \item Second 6 months: 50\,\% \item After: \,\% \end{itemize} & \begin{itemize}\item First 4 months: 35\,\% \item Following 2 months: 40\,\%\end{itemize} & 40\% & 80\% & \begin{itemize}\item First 12 months: 80\,\% \item After: 64\,\%\end{itemize} \\
\multicolumn{5}{|l|}{Other comments}\\
 No access for apprentices and other para-subordinated (a part from experimentatios) & No proof of unemployment required & An IDA requisiti ridotti and an IDA speciale existed too. & Workers fired because of: cessation of business, end of a construction, reduction of personnel, serious company crisis. Also dimission for just cause. An IDE speciale existed too.~ & Duration increased by 12 months in southern regions. An IMO lunga, anticipate and in deroga existed. \\
\hline
\end{tabularx}
\end{sidewaystable}

\end{document}

在此处输入图片描述

答案3

根据@Mico 和@Bernard 答案的组合,使用threeparttable

\documentclass{article}
\usepackage[vmargin=30mm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{adjustbox}
\usepackage{ragged2e}
\usepackage{rotating}
\usepackage{booktabs, tabularx, threeparttable}
\newcolumntype{L}{>{\small\linespread{0.84}\selectfont%
                    \RaggedRight\hspace{0pt}}X}

\usepackage[table, svgnames]{xcolor}
\definecolor{vcolor}{rgb}{0.749,0.749,0.749}
\definecolor{rcolor}{rgb}{0.949,0.949,0.949}
\usepackage{enumitem}

\begin{document}

\begin{sidewaystable}
\setlist[itemize]{nosep, 
                  leftmargin=*,    
                  before=\vspace*{-\baselineskip}, 
                  after =\vspace*{-\baselineskip}
                  }%
    \centering
    \setlength{\tabcolsep}{3pt}
    \setlength{\extrarowheight}{2pt}%
\begin{threeparttable}
Pre-Fornero period (2012)   
\rowcolors{2}{}{rcolor}
    \begin{tabularx}{\linewidth}{@{} >{\hsize=0.8\hsize%
                                       \columncolor{white}[0pt][\tabcolsep]}L
                                                   *{4}{L}
                                     >{\hsize=1.2\hsize%
                                       \columncolor{white}[\tabcolsep][0pt]}L 
                                 @{}}                  
    \midrule[\heavyrulewidth]
    & IDO\tnote{1}  & IDRR\tnote{2} & IDA\tnote{3}   & IDE\tnote{4}   & IMO\tnote{5}       \\
    \specialrule{\lightrulewidth}{\aboverulesep}{0pt}
Firms and sectors
    & All firms, all sector
    & All firms, all sectors
    & All firms, agricultural sector
    & All firms, construction sector and similar
    & Firms with more than 15 employees, industrial sector
      (but not the construction sector), commercial sector
      (firm with more than 50 employees), other minor sectors  \\
Firms and sectors
    & All firms, all sector
    & All firms, all sectors
    & All firms, agricultural sector
    & All firms, construction sector and similar
    & Firms with more than 15 employees, industrial sector
      (but not the construction sector), commercial sector
      (firm with more than 50 employees), other minor sectors  \\
%    \addlinespace
Insurance requirement
    & 2 years & 2 years & 2 years & -- & -- \\
Contribution requirement
    & 52 weeks in the previous 2 years
    & 78 days in the previous 12 months
    & 102 days in the previous 12 months
    & 10 months or 43 weeks
    & 12 months of seniority in the firm \\
Duration
    & \begin{itemize}
        \item Age<50: 8 months
        \item Age>50: 12 months
      \end{itemize}
    & Settled in a single payment
    & = number of days of contribution
    & 90 days
    & \begin{itemize}
        \item Age <40: 12 months
        \item Age 40--50: 24 months
        \item Age >50: 36 months
      \end{itemize} \\
Replacement rate
    & \begin{itemize}
        \item First 6 months: 60\,\%
        \item Second 6 months: 50\,\%
        \item After: 40\%
      \end{itemize}
    & \begin{itemize}
        \item First 4 months: 35\,\%
        \item Foll.\ 2 months: 40\,\%
      \end{itemize}
    & 40\% & 80\%
    & \begin{itemize}
        \item First 12 months: 80\,\%
        \item After: 64\,\%
      \end{itemize} \\
Other comments
    & No access for apprentices and other para-subordinated
      (a part from experimentations)
    & No proof of unemployment required
    & An IDA requisiti ridotti and an IDA speciale existed too.
    & Workers fired because of: cessation of business, end of a
      construction, reduction of personnel, serious company crisis.
      Also dismissal for just cause. An IDE speciale existed too.
    & Duration increased by 12 months in southern regions. An
      IMO lunga, anticipate and in deroga existed. \\
    \bottomrule
    \end{tabularx}
    \begin{tablenotes}[para, flushleft]\footnotesize
\item IDO:  Indennità di disoccupazione ordinaria
\item IDRR: Indennità di disoccupazione a requisiti ridotti
\item IDA:  Indennità di disoccupazione agricola
\item IDE:  Indennità di disoccupazione edile
\item IMO:  Indennità di mobilità ordinaria
    \end{tablenotes}
\end{threeparttable}
\end{sidewaystable}

\end{document}

在此处输入图片描述

相关内容