Adapter le tableau à la page

Nov 02 2020

Ma table est trop large. Quelqu'un sait comment l'adapter à la page?

Voici mon code:


    \begin{table}[]
\scalebox{0.8}{


\begin{tabular}{llll}
\rowcolor[HTML]{9B9B9B} 
{\color[HTML]{000000} \textbf{Activity}} & {\color[HTML]{000000} \textbf{Aspects}} & {\color[HTML]{000000} \textbf{Impacts}} & {\color[HTML]{000000} \textbf{Level of influence}} \\
\rowcolor[HTML]{C0C0C0} 
Anode production &  &  &  \\ \hline
Energy and anode baking & CO$_2$ emissions & Global warming & Global \\ \hline
Anode butts & Emission of SO$_2$, NO$_x$ and fluorides & Negative impact on air, soil and water & Regional, local \\ \hline
 & Emissions of dust & Poor air quality, human health & Local \\ \hline
 & PAH emissions & Human health, accumulates in marine species (e.g. mussels) & Local \\ \hline
Use of cooling water & Emissons to water & Negative impact on the marine environment & Local \\ \hline
\rowcolor[HTML]{C0C0C0} 
Electrolysis, aluminum smelting &  &  &  \\ \hline
Energy and anode consumption & CO$_2$ emissions & Global warming & Global \\ \hline
Anode effects & PFC emissions & Global warming & Global \\ \hline
Anode consumption & SO$_2$ emissions & Environmental acidification, health problems & Regional, local \\ \hline
 & NO$_x$ emissions, fluorides & respiratory diseases,  acid rain & Regional, local \\ \hline
 & Carbon monoxide & ozone precursors & Local \\ \hline
 & SPL &  & Local \\ \hline
 & Metal compounds & Toxic for environment & Local \\ \hline
\rowcolor[HTML]{C0C0C0} 
Casting and remelting &  &  &  \\
Energy consumption & CO$_2$ emissions & Global warming & Global \\ \hline
Fuel consumption & SO$_2$ emissions & Environmental acidification, health problems & Regional, local \\ \hline
Burning & NO$_x$ emissions & respiratory diseases,  acid rain & Regional, local \\ \hline
 & Volatile organic compounds & ozone precursors & Local \\ \hline
Skimming & Emission of dross & Toxic for environment & Local \\ \hline
\end{tabular}}
\end{table}

Réponses

3 Zarko Nov 03 2020 at 00:39

En orientation portrait, avec tabularxet cellspace:

\documentclass{article}
\usepackage{geometry}
\usepackage[table]{xcolor}
\usepackage{booktabs, makecell, tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash\hspace{0pt}%
                    \linespread{0.84}\selectfont}X}
\usepackage[column=O]{cellspace}
    \setlength\cellspacetoplimit{2pt}
    \setlength\cellspacebottomlimit{2pt}
    \addparagraphcolumntypes{L}

\usepackage{mhchem}

\begin{document}
    \begin{table}
    \setlength\tabcolsep{3pt}
    \small
\begin{tabularx}{\linewidth}{@{} O{L} >{\hsize=0.8\hsize}O{L}
                                      >{\hsize=1.2\hsize}O{L} 
                                l
                             @{}}
    \toprule
\textbf{Activity}
    &   \textbf{Aspects}
        &   \textbf{Impacts}
            &   \textbf{\makecell[l]{Level of\\ influence}}    \\
    \specialrule{\lightrulewidth}{\abovetopsep}{0pt}
    \rowcolor{gray!20}
\multicolumn{4}{Ol}{\textbf{Anode production}}   \\
Energy and anode baking
    &   \ce{CO2} emissions
        &   Global warming
            &   Global                              \\
Anode butts
    &   Emission of \ce{SO2}, \ce{NO_x} and fluorides
        &   Negative impact on air, soil and water
            &   Regional, local                     \\
    &   Emissions of dust
        & Poor air quality, human health
            & Local                                 \\
    & PAH emissions
        & Human health, accumulates in marine species (e.g. mussels)
            & Local                                 \\
Use of cooling water
    &   Emissions to water
        &   Negative impact on the marine environment
            &   Local                               \\
    \specialrule{\lightrulewidth}{\abovetopsep}{0pt}
    \rowcolor{gray!30}
\multicolumn{4}{Ol}{\textbf{Electrolysis, aluminum smelting}}\\
Energy and anode consumption
    &   \ce{CO2} emissions
        &   Global warming
            &   Global                              \\
Anode effects
    &   PFC emissions
        &   Global warming
            &   Global                              \\
Anode consumption
    &   \ce{CO2} emissions
        &   Environmental acidification, health problems
            &   Regional, local                     \\
    &   \ce{NO_x} emissions, fluorides
        &   respiratory diseases, acid rain
            &   Regional, local                     \\
    &   Carbon monoxide
        &   ozone precursors
            &   Local                               \\
    & SPL
        &
            &   Local                               \\
    &   Metal compounds
        &   Toxic for environment
            &   Local                               \\
    \specialrule{\lightrulewidth}{\abovetopsep}{0pt}
    \rowcolor{gray!30}
\multicolumn{4}{Ol}{\textbf{Casting and remelting}}\\
Energy consumption
    &   \ce{CO2} emissions
        &   Global warming
            &   Global                          \\
Fuel consumption
    &   \ce{SO2} emissions
            & Environmental acidification, health problems
            & Regional, local                   \\
Burning
    &   \ce{NO_x} emissions
        &   respiratory diseases, acid rain
            &   Regional, local                 \\
    &   Volatile organic compounds
        &   ozone precursors 
            & Local                             \\
Skimming
    &   Emission of dross
        &   Toxic for environment
            &   Local                           \\
    \bottomrule
\end{tabularx}
    \end{table}
\end{document}   

Addenda. Concernant votre commentaire sur la largeur des colonnes:

Les Llargeurs des colonnes sont définies par >{\hsize=<ratio>. \hsize}. Si <ratio>est 1 À cette somme de tous <ratio>devait être égal au nombre de Lcolonnes dans le tableau. Dans votre cas, il devrait être 3 (trois):

> O{L}                   % <--- ratio is 1
>{\hsize=0.8\hsize}O{L}  % <--- ratio is 0.8
>{\hsize=1.2\hsize}O{L}  % <--- ratio is 1.2
                         -------------------       
                                   sum = 3

De cette façon, vous pouvez modifier les ratios entre les Lcolonnes de votre tableau. Par exemple, la largeur de la première colonne du tableau est réduite:

\begin{tabularx}{\linewidth}{@{} 
                 >{\hsize=0.6\hsize}O{L} %  0.8
                                    O{L} %  1.0
                 >{\hsize=1.4\hsize}O{L} %  1.2
                                       l
                             @{}}

En utilisant ce préambule de table dans le produit MWE ci-dessus:

Addendum (2): Si vous aimez avoir du texte justifié dans vos colonnes, n'utilisez pas de Lspécificateur de colonne mais X. Pour conserver certaines fonctionnalités de la Ldéfinition de colonne également dans la Xcolonne, vous devez choisir:

  • à chaque utilisation de l' Xoption d'ajout>{\hspace{0pt}\linespread{0.84}\selectfont}
  • ou défini un nouveau type de colonne, par exemple Y, qui prend en compte les paramètres ci-dessus:
\newcolumntype{Y}{>{\hspace{0pt}\linespread{0.84}\selectfont}X}
% using this, "L" column can be now defined as
\newcolumntype{L}{>{\raggedright\arraybackslash}Y}

Je crois que le moment est venu, que vous vous familiarisiez avec les paramètres de table. Vous pouvez trouver des informations de base à leur sujet dans entrer la description du lien ici . Aide également à expérimenter différents types de colonnes dans le tableau.

2 Mico Nov 03 2020 at 00:04

Voici une solution qui supprime l' adjustboxapproche et permet le saut de ligne automatique dans les quatre colonnes à l'aide du tabularxpackage et de son environnement LaTeX éponyme.

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{tabularx,ragged2e,booktabs}
\newcolumntype{L}[1]{>{\RaggedRight\hsize=#1\hsize%
         \hangafter=1\hangindent=1em}X}
\usepackage[letterpaper,margin=1in]{geometry}
\usepackage{mhchem}
\begin{document}
\begin{table}
\setlength\extrarowheight{2pt}

\begin{tabularx}{\textwidth}{L{0.86}L{1.14}L{1.3}L{0.7}}

\rowcolor[HTML]{9B9B9B} 
\textbf{Activity} & \textbf{Aspects} & 
\textbf{Impacts}  & \textbf{Level of influence} \\
\rowcolor[HTML]{C0C0C0} 
\multicolumn{4}{l}{Anode production}  \\ 
Energy and anode baking & \ce{CO2} emissions & Global warming & Global \\ 
Anode butts & Emission of \ce{SO2}, \ce{NO_x} and fluorides & Negative impact on air, soil and water & Regional, local \\ 
 & Emissions of dust & Poor air quality, human health & Local \\ 
 & PAH emissions & Human health, accumulates in marine species (e.g. mussels) & Local \\ 
Use of cooling water & Emissons to water & Negative impact on the marine environment & Local \\ 
\rowcolor[HTML]{C0C0C0} 
\multicolumn{4}{l}{Electrolysis, aluminum smelting} \\ 
Energy and anode consumption & \ce{CO2} emissions & Global warming & Global \\ 
Anode effects & PFC emissions & Global warming & Global \\ 
Anode consumption & \ce{SO2} emissions & Environmental acidification, health problems & Regional, local \\ 
 & \ce{NO_x} emissions, fluorides & respiratory diseases,  acid rain & Regional, local \\ 
 & Carbon monoxide & ozone precursors & Local \\ 
 & SPL &  & Local \\ 
 & Metal compounds & Toxic for environment & Local \\ 
\rowcolor[HTML]{C0C0C0} 
\multicolumn{4}{l}{Casting and remelting}  \\
Energy consumption & \ce{CO2} emissions & Global warming & Global \\ 
Fuel consumption & \ce{SO2} emissions & Environmental acidification, health problems & Regional, local \\ 
Burning & \ce{NO_x} emissions & respiratory diseases,  acid rain & Regional, local \\ 
 & Volatile organic compounds & ozone precursors & Local \\ 
Skimming & Emission of dross & Toxic for environment & Local \\ 
\bottomrule
\end{tabularx}
\end{table}
\end{document}
Sam Nov 02 2020 at 23:16

À mon humble avis, votre tableau est bien trop large pour une page normale. Comme le montrent les autres réponses, il est possible de l'adapter à la page mais vous vous retrouvez avec beaucoup de texte multiligne qui est difficile à lire dans un tableau car vous vous perdez facilement. Je suggérerais donc d'utiliser l' sidewaystableenvironnement du rotatingpackage et d'avoir le tableau au format paysage dans le document. Cela le rend également beaucoup plus lisible.

De plus, je suggère d'utiliser le mhchempackage pour vos formules chimiques comme le SO 2 .

Enfin, je me suis permis de reformater un peu le tableau pour augmenter la lisibilité du code et du tableau résultant.

\documentclass{article}

\usepackage{booktabs}
\usepackage{array}
\usepackage{multicol}
\usepackage{rotating}

\usepackage{mhchem}

\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}

\begin{sidewaystable}
    \begin{tabular}{
            L{0.2\linewidth}
            L{0.2\linewidth}
            L{0.4\linewidth}
            L{0.2\linewidth}
        }
        \toprule
        
        \textbf{Activity} 
            & \textbf{Aspects} 
            & \textbf{Impacts} 
            & \textbf{Level of influence}\\
        
        \midrule
    
        \multicolumn{4}{l}{\textbf{Anode production}}\\
        Energy and anode baking 
            & \ce{CO2} emissions 
            & Global warming 
            & Global\\
    
        Anode butts 
            & Emission of \ce{SO2}, $\ce{NO_x}$ and fluorides 
            & Negative impact on air, soil and water 
            & Regional, local\\
     
            & Emissions of dust 
            & Poor air quality, human health & Local\\
    
            & PAH emissions 
            & Human health, accumulates in marine species (e.g. mussels) 
            & Local\\
    
        Use of cooling water 
            & Emissons to water 
            & Negative impact on the marine environment 
            & Local\\
        
        \midrule
        
        \multicolumn{4}{l}{\textbf{Electrolysis, aluminum smelting}}\\
        Energy and anode consumption 
            & \ce{CO2} emissions 
            & Global warming 
            & Global\\
            
        Anode effects 
            & PFC emissions 
            & Global warming 
            & Global\\
            
        Anode consumption 
            & \ce{CO2} emissions 
            & Environmental acidification, health problems 
            & Regional, local\\
            
            & $\ce{NO_x}$ emissions, fluorides 
            & respiratory diseases, acid rain 
            & Regional, local\\
            
            & Carbon monoxide 
            & ozone precursors 
            & Local\\
            
            & SPL 
            &  
            & Local\\
            
            & Metal compounds 
            & Toxic for environment 
            & Local\\
            
        \midrule
            
        \multicolumn{4}{l}{\textbf{Casting and remelting}}\\
        Energy consumption 
            & \ce{CO2} emissions 
            & Global warming 
            & Global\\
            
        Fuel consumption 
            & \ce{SO2} emissions 
            & Environmental acidification, health problems 
            & Regional, local\\
            
        Burning 
            & $\ce{NO_x}$ emissions 
            & respiratory diseases, acid rain 
            & Regional, local\\
            
            & Volatile organic compounds 
            & ozone precursors & Local\\
            
        Skimming 
            & Emission of dross 
            & Toxic for environment 
            & Local\\
        
        \bottomrule
    \end{tabular}
\end{sidewaystable}

\end{document}


PS: Veuillez fournir un document d'exemple de travail minimal (MWE) à l'avenir.