使表格适合页面

使表格适合页面

我一直试图通过 tablesgenerator 创建一个(简单)表格,但到目前为止输出的结果并不令人满意。我想创建下表(表 4. 所选内容摘要....),但它不适合我的页面。要么它太大,要么当我使用\resizebox函数或时它变得太小adjustbox需要桌子 我在这个论坛上查找了很多信息并尝试了很多方法,但迄今为止都没有成功。在此处输入图片描述 以下代码绘制了上面的表格(表 3.1)。希望有人能帮助我!非常感谢!

\documentclass{article}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{tabularx}
\begin{document}


       \begin{table}[]
    \centering
    \caption{My caption}
    \label{my-label}
    \resizebox{\textwidth}{!}{%
    \begin{tabular}{@{}lllllll@{}}
    \toprule
    \textbf{Model}          & \textbf{Breach morphology}                    & \textbf{Flow}                               & \textbf{Sediment transport capacity}         & \textbf{Geomechanics}                                  & \textbf{Solution method}                         & \textbf{Remarks}                          \\ \midrule
                            & 1D Exner equation                             & 1D St.Venant equations                      & Multiple formulas                            & Longitudinal slope stability                           & Fine difference,uncoupled                        & Overtopping, no lateral erosion           \\
    DEICH\_N1 and DEICH\_N2 & Evolution from 1D/2D Exner quation            & Shallo water equations                      & Nine different formulas availabe             &                                                        & 1D/2D numerical model, uncoupled                 &                                           \\
                            & 2D Exner equation                             & 2D shallow water equations                  & Erosion formula from WEPP, USDA              &                                                        & 2D numerical model, uncoupled                    & Validated with Norweigian field tests     \\
                            & Clear-water scour                             & 2D shallow water equations                  & Chen and Anderson's formula for erosion rate & 3D slope stability                                     & 2D TVD finite differnce, uncoupled               & Noncohesive dam, overtopping              \\
                            & 2D Exner equation                             & 2D shallow water equations                  & Formulas for bed-load and suspended load     & Lateral erosion, vertical erosion, and slope stability & 2D finite volume ( Roe and HLL), uncoupled       & Noncohesive levee, overtopping            \\
                            & 2D nonequilibrium sediment transport equation & 2D shallow water equations                  & Formula for bed-load                         & Lateral erosion,vertical erosion, and slope stability  & 2D finite volume (Roe's Riemann solver), coupled & Noncohesive overtopping                   \\
                            & 2D nonequilibrium sediment transport equation & 2D shallow water equations with wave-action & Soulsby formula                              & Bed avalanching                                        & 2D finite difference, uncoupled                  & Noncohesive dune and barrier, overtopping \\
                            & 1D/2D Nonequilibrium total-load tranport      & Generelized shallow water equations         & Wu etal. total-load capacity formula         & Lateral erosion and slope stability ( repose angle)    & 1D/2D finite volume (HLL) scheme, coupled        & Noncohesive dam and levee, overtopping    \\
                            & 2D nonequilirbium sediment transport          & Generalized shallow water equations         & Modified Meyer-Peter and Müller bed-load     & Slope stability (repose angle)                         & Finite volume (HLLC) scheme, coupled             & Landslide dam, overtopping                \\ \bottomrule
    \end{tabular}%
    }
    \end{table}

\end{document}

答案1

首先,表格中的数据看起来很庞大,将其放入一个表格中可能会牺牲工作的可读性。如果您可以稍微缩小表格内容或重新设计表格,那将是一件很棒的事情。除此之外,我还做了许多改进:

  1. 我使用了sidewaystable旋转包中的环境;这将为表格列腾出更多空间。
  2. 我删除了\resizebox{\textwidth}{!}并使用了tabularx
  3. 为了避免出现太多奇怪的连字符,并且需要完全对齐,我使用了\raggedright
  4. 为了获得更多空间,我将默认值tabcolsep从更改4pt2pt
  5. 使用\sffamily还可以提供更多的空间。
  6. 最后,使用\small将节省一些额外的空间而不会牺牲可读性。

正如我之前所说,在内容缩减和表格重新设计都失败后,上述方法应该是您的最后手段。

\documentclass{article}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{tabularx,rotating}
\usepackage[margin=1in]{geometry}
\usepackage{ragged2e}
\begin{document}

    \setlength{\tabcolsep}{2pt}
    \begin{sidewaystable}
    \small\sffamily\centering
    \caption{My caption}
    \label{my-label}
    \begin{tabularx}{\textwidth}{@{}*7{>{\raggedright\arraybackslash}X}@{}}
    \toprule
    \textbf{Model}          & \textbf{Breach morphology}                    & \textbf{Flow}                               & \textbf{Sediment transport capacity}         & \textbf{Geomechanics}                                  & \textbf{Solution method}                         & \textbf{Remarks}                          \\ \midrule
                            & 1D Exner equation                             & 1D St.Venant equations                      & Multiple formulas                            & Longitudinal slope stability                           & Fine difference,uncoupled                        & Overtopping, no lateral erosion           \\
    DEICH\_N1 and DEICH\_N2 & Evolution from 1D/2D Exner quation            & Shallo water equations                      & Nine different formulas availabe             &                                                        & 1D/2D numerical model, uncoupled                 &                                           \\
                            & 2D Exner equation                             & 2D shallow water equations                  & Erosion formula from WEPP, USDA              &                                                        & 2D numerical model, uncoupled                    & Validated with Norweigian field tests     \\
                            & Clear-water scour                             & 2D shallow water equations                  & Chen and Anderson's formula for erosion rate & 3D slope stability                                     & 2D TVD finite differnce, uncoupled               & Noncohesive dam, overtopping              \\
                            & 2D Exner equation                             & 2D shallow water equations                  & Formulas for bed-load and suspended load     & Lateral erosion, vertical erosion, and slope stability & 2D finite volume ( Roe and HLL), uncoupled       & Noncohesive levee, overtopping            \\
                            & 2D nonequilibrium sediment transport equation & 2D shallow water equations                  & Formula for bed-load                         & Lateral erosion,vertical erosion, and slope stability  & 2D finite volume (Roe's Riemann solver), coupled & Noncohesive overtopping                   \\
                            & 2D nonequilibrium sediment transport equation & 2D shallow water equations with wave-action & Soulsby formula                              & Bed avalanching                                        & 2D finite difference, uncoupled                  & Noncohesive dune and barrier, overtopping \\
                            & 1D/2D Nonequilibrium total-load tranport      & Generelized shallow water equations         & Wu etal. total-load capacity formula         & Lateral erosion and slope stability ( repose angle)    & 1D/2D finite volume (HLL) scheme, coupled        & Noncohesive dam and levee, overtopping    \\
                            & 2D nonequilirbium sediment transport          & Generalized shallow water equations         & Modified Meyer-Peter and Müller bed-load     & Slope stability (repose angle)                         & Finite volume (HLLC) scheme, coupled             & Landslide dam, overtopping                \\ \bottomrule
    \end{tabularx}%
    \end{sidewaystable}

\end{document}

在此处输入图片描述

答案2

假如说:

  • 可以增加文本宽度(通过使用\usepackage[margin=25mm]{geometry}
  • 单元格内容可以分成多行
  • 表格内容的字体大小为\footnotesize

然后你会得到:

在此处输入图片描述

如果这不令人满意,那么您应该考虑上述评论。

编辑:我认识到在答案的第一个版本中我忘记添加代码示例(姆韦)。 这是:

\documentclass{article}
\usepackage[margin=25mm]{geometry}
\usepackage{graphicx}
\usepackage{booktabs, tabularx}
\newcolumntype{R}{>{\raggedright\arraybackslash}X}

%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{table}
\caption{My caption}
    \label{my-label}
\footnotesize\sffamily
\setlength{\tabcolsep}{2pt}
\begin{tabularx}{\textwidth}{@{}*7{R}@{}}
    \toprule
\textbf{Model}
    & \textbf{Breach morphology}
        & \textbf{Flow}
            & \textbf{Sediment transport capacity}
                & \textbf{Geomechanics}
                    & \textbf{Solution method}
                        & \textbf{Remarks}                                          \\
    \midrule
    & 1D Exner equation                     & 1D St.Venant equations
    & Multiple formulas                     & Longitudinal slope stability
    & Fine difference,uncoupled             & Overtopping, no lateral erosion       \\
    \addlinespace
DEICH\_N1 and DEICH\_N2
    & Evolution from 1D/2D Exner quation    & Shallo water equations
    & Nine different formulas availabe      &                                                        & 1D/2D numerical model, uncoupled      &                                       \\
    \addlinespace
    & 2D Exner equation                     & 2D shallow water equations
    & Erosion formula from WEPP, USDA       &
    & 2D numerical model, uncoupled         & Validated with Norweigian field tests \\
    \addlinespace
    & Clear-water scour                     & 2D shallow water equations
    & Chen and Anderson's formula for erosion rate
                                            & 3D slope stability                                    
    & 2D TVD finite differnce, uncoupled    & Noncohesive dam, overtopping          \\
    \addlinespace
    & 2D Exner equation                     & 2D shallow water equations
    & Formulas for bed-load and suspended load
                                    & Lateral erosion, vertical erosion, and slope stability
    & 2D finite volume ( Roe and HLL), uncoupled
                                    & Noncohesive levee, overtopping                \\
    \addlinespace
    & 2D nonequilibrium sediment transport equation
                                    & 2D shallow water equations
    & Formula for bed-load          & Lateral erosion,vertical erosion, and slope stability
    & 2D finite volume (Roe's Riemann solver), coupled
                                    & Noncohesive overtopping                       \\
    \addlinespace
    & 2D nonequilibrium sediment transport equation
                                    & 2D shallow water equations with wave-action
    & Soulsby formula               & Bed avalanching
    & 2D finite difference, uncoupled       & Noncohesive dune and barrier, overtopping \\
    \addlinespace
    & 1D/2D Nonequilibrium total-load tranport
                                    & Generelized shallow water equations
    & Wu etal. total-load capacity formula
                                    & Lateral erosion and slope stability ( repose angle)
    & 1D/2D finite volume (HLL) scheme, coupled
                                    & Noncohesive dam and levee, overtopping    \\
    \addlinespace
    & 2D nonequilirbium sediment transport
                                    & Generalized shallow water equations
    & Modified Meyer-Peter and Müller bed-load
                                    & Slope stability (repose angle)
    & Finite volume (HLLC) scheme, coupled
                                    & Landslide dam, overtopping                \\
    \bottomrule
\end{tabularx}
    \end{table}

\end{document}

答案3

如果您不能大幅加宽文本块,并且您不想(或不允许)切换到更小的字体大小,那么您将不得不切换到环境longtable,因为材料根本无法放在单个页面上。

在此处输入图片描述


在此处输入图片描述

\documentclass{article}
\usepackage{booktabs,longtable,array,ragged2e}
\newcolumntype{P}[1]{>{\RaggedRight\arraybackslash\hspace{0pt}}p{#1}}

\newlength\firstcolwidth
\settowidth\firstcolwidth{DEICH\_N1}
\setlength\tabcolsep{4pt} % default: 6pt
\newlength\othercolwidth
\setlength\othercolwidth{\dimexpr\textwidth-\firstcolwidth-12\tabcolsep\relax}
\setlength\othercolwidth{\dimexpr\othercolwidth/6\relax}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\begin{document}

\begin{longtable}{@{} p{\firstcolwidth} 
    *{6}{P{\othercolwidth}} @{}}
    \caption{My caption} \label{tab:my-label}\\
    \toprule
Model & Breach morphology & Flow & Sediment transport capacity & Geomechanics & Solution method & Remarks \\ 
\midrule
\endfirsthead
\multicolumn{7}{@{}l@{}}{Table \ref{tab:my-label}, continued}\\ \addlinespace
\toprule
Model & Breach morphology & Flow & Sediment transport capacity & Geo\-mechanics & Solution method & Remarks \\ 
\midrule
\endhead

\midrule
\multicolumn{7}{@{}r@{}}{continued on following page}\\
\endfoot
\bottomrule
\endlastfoot

                            & 1D Exner equation                             & 1D St. Venant equations                      & Multiple formulas                            & Longitudinal slope stability                           & Fine difference, uncoupled                        & Overtopping, no lateral erosion           \\ \addlinespace
DEICH\_N1 and DEICH\_N2     & Evolution from 1D/2D Exner equation            & Shallow water equations                      & Nine different formulas available             &                                                        & 1D/2D numerical model, uncoupled                 &                                           \\ \addlinespace
                            & 2D Exner equation                             & 2D shallow water equations                  & Erosion formula from WEPP, USDA              &                                                        & 2D numerical model, uncoupled                    & Validated with Norwegian field tests     \\ \addlinespace
                            & Clear-water scour                             & 2D shallow water equations                  & Chen and Anderson's formula for erosion rate & 3D slope stability                                     & 2D TVD finite differnce, uncoupled               & Noncohesive dam, overtopping              \\ \addlinespace
                            & 2D Exner equation                             & 2D shallow water equations                  & Formulas for bed-load and suspended load     & Lateral erosion,  vertical erosion, and slope stability & 2D finite volume (Roe and HLL), uncoupled       & Noncohesive levee, overtopping            \\ \addlinespace
                            & 2D nonequilibrium sediment transport equation & 2D shallow water equations                  & Formula for bed-load                         & Lateral erosion, vertical erosion, and slope stability  & 2D finite volume (Roe's Riemann solver), coupled & Noncohesive overtopping                   \\ %\addlinespace
                            & 2D nonequilibrium sediment transport equation & 2D shallow water equations with wave-action & Soulsby formula                              & Bed avalanching                                        & 2D finite difference, uncoupled                  & Noncohesive dune and barrier, overtopping \\ \addlinespace
                            & 1D/2D Nonequilibrium total-load tranport      & Generalized shallow water equations         & Wu et~al.\ total-load capacity formula         & Lateral erosion and slope stability (repose angle)    & 1D/2D finite volume (HLL) scheme, coupled        & Noncohesive dam and levee, overtopping    \\ \addlinespace
                            & 2D non\-equilib\-rium sediment transport          & Generalized shallow water equations         & Modified Meyer-Peter and Müller bed-load     & Slope stability (repose angle)                         & Finite volume (HLLC) scheme, coupled             & Landslide dam, overtopping                \\ 
\end{longtable}

\end{document}

相关内容