1

enter image description here

My table is to wide. Anyone know how to make it fit the page?

This is my 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}

Lisa
  • 35

3 Answers3

3

In portrait orientation, with tabularx and 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}

enter image description here

Addendum. Regarding your comment about width of columns:

Columns L widths are set by >{\hsize=<ratio>. \hsize}. If <ratio> is 1 At this sum of all <ratio> had to be equal to number od L columns in table. In your case it should be 3 (three):

> 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

On this way you can change ratios beteen L columns in your table. For example, table is narrowed first column width:

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

Using this table preamble in above MWE produce:

enter image description here

Addendum (2): If you like to have justified text in your columns, than don't use L column specifier but X. To preserve some features of L column definition also in in X column, you have to choices:

  • at each use of X add option >{\hspace{0pt}\linespread{0.84}\selectfont}
  • or defined new column type, for example Y, which consider above settings:
\newcolumntype{Y}{>{\hspace{0pt}\linespread{0.84}\selectfont}X}
% using this, "L" column can be now defined as
\newcolumntype{L}{>{\raggedright\arraybackslash}Y}

I believe, that now is time, that you make yourself more familiar with table settings. Basics about them you can find in enter link description here. Also helps experimenting with different column types in table.

Zarko
  • 296,517
  • Thank You, I really liked your layout. However, when I tried to copy-paste the code, it is not working properly. – Lisa Nov 03 '20 at 10:29
  • @Lisa, what not work? Provided MWE is tested and result of compilation is presented. So you are change something ... – Zarko Nov 03 '20 at 10:34
  • I found the problem, thanks for the nice table! – Lisa Nov 03 '20 at 11:08
  • @Lisa, nice to hear this. Now You have three worked solutions, so you can accept this one, which to your opinion on the best way solve your problem (by clicking on the check mark, which is at top left side of selected answer). – Zarko Nov 03 '20 at 12:31
  • How can I make the activity column smaller? Any quick fix for this? I have used the table as a template for other tables. However, I need this first column to be smaller (more narrow) – Lisa Nov 18 '20 at 14:15
  • 1
    @Lisa, see addendum to answer. – Zarko Nov 18 '20 at 16:13
  • Thank you. I tried to use >{\hsize= x \hsize} in front of all three O{L}. However, it did not accept this (where x1+x2+x3 = 3). Say I don't want one column to have ratio 1. – Lisa Nov 19 '20 at 10:30
  • And also, is it possible to Justify the text in the table, distribute the text evenly between the margins – Lisa Nov 19 '20 at 10:37
  • @Lisa, yes, it is possible. Instead of L just use X. However, this is not a very smart idea, since columns are narrow and text will consequently looks (very) ugly. Rathe before try the second addendum to answer, will be added asap. – Zarko Nov 19 '20 at 10:44
  • Yes, thank you so much for all help, Zarko. I tried to look at the webpage, however I could not find the answer on why >{\hsize= x \hsize} in front of all three O{L} does not work. – Lisa Nov 19 '20 at 11:37
  • @Lisa, new problem, new question. Please! – Zarko Nov 19 '20 at 11:50
  • Oh, okay, sorry, I'm new to the forum. I will post a new question! – Lisa Nov 19 '20 at 14:00
2

Here's a solution that does away with the adjustbox approach and permits automatic line breaking in all four columns with the help of the tabularx package and its eponymous LaTeX environment.

enter image description here

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

Mico
  • 506,678
0

IMHO, your table is way too wide for a normal page. As can be seen by the other answers, it's possible to fit it to the page but you end up with a lot of multiline text which is hard to read in a table as you get easily lost. I would thus suggest using the sidewaystable environment of the rotating package and have the table in landscape format in the document. This also makes it way more readable.

Moreover, I suggest using the mhchem package for your chemical formulas like SO2.

Last but not least, I allowed myself to reformat the table a bit to increase the readability of both the code and the resulting table.

\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} 
        &amp; \textbf{Aspects} 
        &amp; \textbf{Impacts} 
        &amp; \textbf{Level of influence}\\

    \midrule

    \multicolumn{4}{l}{\textbf{Anode production}}\\
    Energy and anode baking 
        &amp; \ce{CO2} emissions 
        &amp; Global warming 
        &amp; Global\\

    Anode butts 
        &amp; Emission of \ce{SO2}, $\ce{NO_x}$ and fluorides 
        &amp; Negative impact on air, soil and water 
        &amp; Regional, local\\

        &amp; Emissions of dust 
        &amp; Poor air quality, human health &amp; Local\\

        &amp; PAH emissions 
        &amp; Human health, accumulates in marine species (e.g. mussels) 
        &amp; Local\\

    Use of cooling water 
        &amp; Emissons to water 
        &amp; Negative impact on the marine environment 
        &amp; Local\\

    \midrule

    \multicolumn{4}{l}{\textbf{Electrolysis, aluminum smelting}}\\
    Energy and anode consumption 
        &amp; \ce{CO2} emissions 
        &amp; Global warming 
        &amp; Global\\

    Anode effects 
        &amp; PFC emissions 
        &amp; Global warming 
        &amp; Global\\

    Anode consumption 
        &amp; \ce{CO2} emissions 
        &amp; Environmental acidification, health problems 
        &amp; Regional, local\\

        &amp; $\ce{NO_x}$ emissions, fluorides 
        &amp; respiratory diseases, acid rain 
        &amp; Regional, local\\

        &amp; Carbon monoxide 
        &amp; ozone precursors 
        &amp; Local\\

        &amp; SPL 
        &amp;  
        &amp; Local\\

        &amp; Metal compounds 
        &amp; Toxic for environment 
        &amp; Local\\

    \midrule

    \multicolumn{4}{l}{\textbf{Casting and remelting}}\\
    Energy consumption 
        &amp; \ce{CO2} emissions 
        &amp; Global warming 
        &amp; Global\\

    Fuel consumption 
        &amp; \ce{SO2} emissions 
        &amp; Environmental acidification, health problems 
        &amp; Regional, local\\

    Burning 
        &amp; $\ce{NO_x}$ emissions 
        &amp; respiratory diseases, acid rain 
        &amp; Regional, local\\

        &amp; Volatile organic compounds 
        &amp; ozone precursors &amp; Local\\

    Skimming 
        &amp; Emission of dross 
        &amp; Toxic for environment 
        &amp; Local\\

    \bottomrule
\end{tabular}

\end{sidewaystable}

\end{document}

table


PS: Please provide a minimal working example (MWE) document in the future.

Sam
  • 2,958