Dopasuj tabelę do strony
Mój stół jest za szeroki. Czy ktoś wie, jak dopasować go do strony?
To jest mój kod:
\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}
Odpowiedzi
W orientacji pionowej z tabularxi 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}
Uzupełnienie. Odnośnie twojego komentarza na temat szerokości kolumn:
LSzerokości kolumn są ustawiane przez >{\hsize=<ratio>. \hsize}. Jeśli <ratio>wynosi 1 W tej sumie suma wszystkich <ratio>musiała być równa liczbie Lkolumn w tabeli. W twoim przypadku powinno to być 3 (trzy):
> 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
W ten sposób możesz zmienić proporcje między Lkolumnami w swojej tabeli. Na przykład tabela jest zawężana do szerokości pierwszej kolumny:
\begin{tabularx}{\linewidth}{@{}
>{\hsize=0.6\hsize}O{L} % 0.8
O{L} % 1.0
>{\hsize=1.4\hsize}O{L} % 1.2
l
@{}}
Korzystając z tej preambuły tabeli w powyższej tabeli MWE daje:
Dodatek (2): Jeśli chcesz mieć wyjustowany tekst w swoich kolumnach, nie używaj Lspecyfikatora kolumny, ale X. Aby zachować niektóre cechy Ldefinicji kolumny również w Xkolumnie, musisz wybrać:
- przy każdym użyciu
Xopcji dodawania>{\hspace{0pt}\linespread{0.84}\selectfont} - lub zdefiniowany nowy typ kolumny, na przykład
Y, który uwzględnia powyższe ustawienia:
\newcolumntype{Y}{>{\hspace{0pt}\linespread{0.84}\selectfont}X}
% using this, "L" column can be now defined as
\newcolumntype{L}{>{\raggedright\arraybackslash}Y}
Uważam, że nadszedł czas, abyś lepiej zapoznał się z ustawieniami stołu. Podstawy na ich temat znajdziesz w opisie odnośnika tutaj . Pomaga także w eksperymentowaniu z różnymi typami kolumn w tabeli.
Oto rozwiązanie, które eliminuje to adjustboxpodejście i pozwala na automatyczne łamanie wierszy we wszystkich czterech kolumnach za pomocą tabularxpakietu i jego tytułowego środowiska 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}
IMHO, Twój stół jest o wiele za szeroki na normalną stronę. Jak widać po innych odpowiedziach, możliwe jest dopasowanie go do strony, ale w rezultacie otrzymujesz dużo tekstu wielowierszowego, który jest trudny do odczytania w tabeli, ponieważ łatwo się zgubisz. Dlatego sugerowałbym użycie sidewaystableśrodowiska rotatingpakietu i ustawienie tabeli w dokumencie w formacie poziomym. Dzięki temu jest bardziej czytelny.
Ponadto sugeruję użycie mhchempakietu do twoich wzorów chemicznych, takich jak SO 2 .
Wreszcie, pozwoliłem sobie nieco przeformatować tabelę, aby zwiększyć czytelność zarówno kodu, jak i wynikowej tabeli.
\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: Proszę w przyszłości przedstawić minimalny roboczy przykład (MWE).