使表格适合页面

使表格适合页面

在此处输入图片描述

我的表格太宽了。有人知道如何让它适合页面吗?

这是我的代码:


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

答案1

在纵向模式下,使用tabularxcellspace

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

在此处输入图片描述

附录。 关于您对列宽的评论:

L宽由 设定>{\hsize=<ratio>. \hsize}。如果<ratio>为 1,则所有列的总和<ratio>必须等于L表中的列数。在您的例子中,它应该是 3(三):

> 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

通过这种方式,您可以更改L表格中各列之间的比例。例如,表格的第一列宽度变窄:

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

使用上述 MWE 中的此表序言生成:

在此处输入图片描述

附录(2): 如果您希望在列中使用对齐文本,则不要使用L列说明符,而是使用。为了在列中X保留列定义的某些功能,您必须做出选择:LX

  • 每次使用X添加选项时>{\hspace{0pt}\linespread{0.84}\selectfont}
  • 或者定义新的列类型,例如Y,考虑上述设置:
\newcolumntype{Y}{>{\hspace{0pt}\linespread{0.84}\selectfont}X}
% using this, "L" column can be now defined as
\newcolumntype{L}{>{\raggedright\arraybackslash}Y}

我相信,现在是时候让你更熟悉餐桌布置了。有关餐桌布置的基础知识,你可以在这里找到在此处输入链接描述。还有助于试验表中的不同列类型。

答案2

这里有一个解决方案,它摒弃了这种adjustbox方法,并借助该tabularx软件包及其同名的 LaTeX 环境允许在所有四列中自动换行。

在此处输入图片描述

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

答案3

恕我直言,您的表格对于普通页面来说太宽了。从其他答案可以看出,可以将其放入页面,但最终会得到很多多行文本,这些文本在表格中很难阅读,因为您很容易迷失方向。因此,我建议使用包sidewaystable的环境rotating,并在文档中以横向格式显示表格。这也使其更具可读性。

此外,我建议使用该mhchem包来处理你的化学公式,比如 SO 2

最后但同样重要的一点是,我允许自己重新格式化表格以增加代码和结果表的可读性。

\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:请提供最小 在职的将来的示例(MWE)文档。

相关内容