2

First of all, I am starting in LaTeX, so please excuse for any beginner's mistake.

I know this question seems to be recurrent here, but I couldn't find any solution to my problem.

I often times have a problem where a table does not fit the margins of the document. Therefore, I am curious to know: what is the general best strategy to make a table fit the page width?

I am really focused on switching from Word to LaTeX, and satisfied for most of the tasks, except for when I have to insert a table, where sometimes I feel like I am wasting too much time.

Specifically, this is the table I am grasping with:

\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}

There is more text in the same page as the table, so rotating that page as is not an option for me.

Any tip much appreciated.

  • 1
    Welcome to TeX.SX! Your column content is too wide, make it wrap with other column types. – user31729 Nov 3 '15 at 20:58
3

This is only a small suggestion:

Use special wrapping column types, defined with \newcolumntype (see the definitions below) for left or centered columns.

It's possible to say *{2}{your column type} in order to repeat the same column type twice (or use another number ;-))

\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}
  • Many thanks for the answer, Christian. The table looks fantastic now. I have one question, though. Do the new column definitions apply to all tables in my document? Where are the arguments in the table that make the new definition apply only to it? – thiagoveloso Nov 3 '15 at 21:17
  • 1
    @thiagoveloso: They can be used in any tabular, but you have to explicitly write them of course. They come into action here: {@{}*{2}{L{0.25\textwidth}}C{0.4\textwidth}@{}} where I defined 2 L - type and one C - type column – user31729 Nov 3 '15 at 21:20
  • Cool, thanks! I've accepted your answer, since it preserves the bulk of the code and requires the least packages. – thiagoveloso Nov 3 '15 at 21:28
3

Considering you condition of placing table, there are two solution:

  • select so small fonts, that table can fit within text width
  • allowed line breaks in cells qith loong text.

For second posibilities is advisable solution . With help of \tabularx (for fit table into text width and ability to broke cell content into more lines) and `makecell`` (for simple setting of columns header) I obtain the following:

enter image description here

MWE is:

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.