首先,我刚刚开始LaTeX
,所以如果初学者犯了什么错误,请多包涵。
我知道这个问题似乎在这里反复出现,但我找不到任何解决我的问题的方法。
我经常遇到表格与文档边距不匹配的问题。因此,我很好奇:使表格适合页面宽度的最佳策略是什么?
我非常专注于从 Word 切换到LaTeX
,并且对大多数任务都感到满意,除了必须插入表格的时候,有时我觉得自己浪费了太多时间。
具体来说,这是我掌握的表格:
\documentclass[12pt]{article}
% Load required packages
\usepackage{siunitx} % for units
\usepackage[left=1.5in,right=1in,top=1in,bottom=1in]{geometry} % specify margins
\usepackage{float} % prevent figures to be moved to a different page
\usepackage{booktabs} % for better looking tables
\usepackage{caption} % to increase space between table and caption
\captionsetup[table]{skip=10pt} % reduce space between table and its title
\begin{document}
\begin{table}[H]
\centering
\caption{List of CMIP5 global models used in this study, showing horizontal resolution}
\label{cmip5-models}
\begin{tabular}{@{}lcc@{}}
\toprule
\multicolumn{1}{c}{\textbf{Model acronym}} & \multicolumn{1}{c}{\textbf{Modelling centre}} & \textbf{\begin{tabular}[c]{@{}c@{}}Atmospheric component \\ resolution (lat/lon)\end{tabular}} \\ \midrule
CanESM2 & Canadian Centre for Climate Modelling and Analysis & 2.8\si{\degree} x 2.8\si{\degree} \\
GFDL-ESM2M & NOAA Geophysical Fluid Dynamics Laboratory & 2.0\si{\degree} x 2.5\si{\degree} \\
INMCM4 & Institute for Numerical Mathematics & 1.5\si{\degree} x 2.0\si{\degree} \\
NorESM1-M & Norwegian Climate Centre & 1.9\si{\degree} x 2.5\si{\degree} \\
MRI-CGCM3 & Meteorological Research Institute & 1.1\si{\degree} x 1.1\si{\degree} \\ \bottomrule
\end{tabular}
\end{table}
\end{document}
表格所在页面上有更多文本,因此旋转该页面对我来说不是一个选择。
任何建议都非常感谢。
答案1
这只是一个小建议:
使用特殊的包装列类型,定义为\newcolumntype
(参见下面的定义)左列或居中列。
可以说*{2}{your column type}
为了重复相同的列类型两次(或使用另一个数字;-))
\documentclass[12pt]{article}
% Load required packages
\usepackage{siunitx} % for units
\usepackage[left=1.5in,right=1in,top=1in,bottom=1in]{geometry} % specify margins
\usepackage{float} % prevent figures to be moved to a different page
\usepackage{booktabs} % for better looking tables
\usepackage{caption} % to increase space between table and caption
\usepackage{array}
\captionsetup[table]{skip=10pt} % reduce space between table and its title
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\begin{document}
\begin{table}[H]
\centering
\caption{List of CMIP5 global models used in this study, showing horizontal resolution}
\label{cmip5-models}
\begin{tabular}{@{}*{2}{L{0.25\textwidth}}C{0.4\textwidth}@{}}
\toprule
\multicolumn{1}{c}{\textbf{Model acronym}} & \multicolumn{1}{c}{\textbf{Modelling centre}} & \textbf{Atmospheric component resolution (lat/lon)} \\ \midrule
CanESM2 & Canadian Centre for Climate Modelling and Analysis & 2.8\si{\degree} x 2.8\si{\degree} \\
GFDL-ESM2M & NOAA Geophysical Fluid Dynamics Laboratory & 2.0\si{\degree} x 2.5\si{\degree} \\
INMCM4 & Institute for Numerical Mathematics & 1.5\si{\degree} x 2.0\si{\degree} \\
NorESM1-M & Norwegian Climate Centre & 1.9\si{\degree} x 2.5\si{\degree} \\
MRI-CGCM3 & Meteorological Research Institute & 1.1\si{\degree} x 1.1\si{\degree} \\ \bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
考虑到您摆放桌子的情况,有两种解决方案:
- 选择很小的字体,以便表格可以适合文本宽度
- 允许在长文本单元格中换行。
对于第二种可能性,建议采用以下解决方案。借助\tabularx
(用于将表格适合文本宽度以及将单元格内容分成更多行的能力)和“makecell”(用于简单设置列标题),我获得了以下结果:
MWE 是:
\documentclass[12pt]{article}
% Load required packages
\usepackage{siunitx} % for units
\usepackage[left=1.5in,right=1in,top=1in,bottom=1in]{geometry} % specify margins
\usepackage{float} % prevent figures to be moved to a different page
\usepackage{booktabs,makecell,tabularx} \renewcommand\theadfont{\bfseries}
\usepackage{ragged2e} % for better looking tables
\usepackage{caption} % to increase space between table and caption
\captionsetup[table]{skip=10pt} % reduce space between table and its title
\usepackage{showframe}
\begin{document}
\begin{table}[h]
\centering
\caption{List of CMIP5 global models used in this study, showing horizontal resolution}
\label{cmip5-models}
\begin{tabularx}{\textwidth}{l >{\RaggedRight\arraybackslash}X c}
\toprule
\thead{Model acronym}
& \thead{Modelling centre}
& \thead{Atmospheric component \\ resolution (lat/lon)} \\
\midrule
CanESM2 & Canadian Centre for Climate Modelling and Analysis
& 2.8\si{\degree} x 2.8\si{\degree} \\
GFDL-ESM2M & NOAA Geophysical Fluid Dynamics Laboratory
& 2.0\si{\degree} x 2.5\si{\degree} \\
INMCM4 & Institute for Numerical Mathematics
& 1.5\si{\degree} x 2.0\si{\degree} \\
NorESM1-M & Norwegian Climate Centre
& 1.9\si{\degree} x 2.5\si{\degree} \\
MRI-CGCM3 & Meteorological Research Institute
& 1.1\si{\degree} x 1.1\si{\degree} \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}