1

This is my code, i don't know how to write a tabel on my own yet, so i used an online maker to do this, how do i make sure that the table won't go over my textwidth?

\begin{table}[h]
\begin{tabular}{cccl}
\hline
                                          & \textbf{Fremstilling}                                                                                         & \textbf{Brug}                                                                                                                         & \multicolumn{1}{c}{\textbf{Bortskaffelse}}                                                                        \\ \hline
\multicolumn{1}{|c|}{\textbf{Materiale}}  & \multicolumn{1}{|c|}{Stål (9,95kg)}                                                                           & \multicolumn{1}{|c|}{Energiforbrug til mekanisme}                                                                                     & \multicolumn{1}{|l|}{Energiforbrug til omsmeltning}                                                               \\ \hline
\multicolumn{1}{|c|}{\textbf{Energi}}     & \multicolumn{1}{|c|}{3133,16MJ}                                                                               & \multicolumn{1}{|c|}{\begin{tabular}[c]{@{}c@{}}Nok energi til at trække 26.2N hver\\   gang, at anordningen aktiveres.\end{tabular}} & \multicolumn{1}{|l|}{846,8MJ}                                                                                     \\ \hline
\multicolumn{1}{|c|}{\textbf{Kemikalier}} & \multicolumn{1}{|c|}{-}                                                                                       & \multicolumn{1}{|c|}{Eventuel smørelse}                                                                                               & \multicolumn{1}{|l|}{-}                                                                                           \\ \hline
\multicolumn{1}{|c|}{\textbf{Andet}}      & \multicolumn{1}{|c|}{\begin{tabular}[c]{@{}c@{}}Slibning, eventuel galvanisering\\   (rustfrit)\end{tabular}} & \multicolumn{1}{|c|}{Vedligeholdelse, udskiftning af pigge}                                                                           & \multicolumn{1}{|l|}{\begin{tabular}[c]{@{}c@{}}Genanvendelse af stål (10MJ/kg til\\   omsmeltning)\end{tabular}} \\ \hline
\end{tabular}
\end{table}
  • 2
    Generally, it is up to you to make sure your table does not extend into the right margin. If it has that tendency, you can either reorganize your data presentation to avoid it, or you can, as a last resort, shrink the whole table to fit. But the latter solution will shrink your table fontsize, as well. – Steven B. Segletes Dec 5 '13 at 13:12
1

Here's one possibility:

\documentclass{article}
\usepackage[margin=3cm]{geometry} % set margins smaller (YMMV)
\usepackage{lmodern} % for unicode support
\usepackage{booktabs} % for publication-quality tables
\usepackage{tabularx} % for column width balancing
\usepackage{siunitx} % for typesetting physical quantities with units
\sisetup{% setup for your locale (Denmark)
  output-decimal-marker = {,},
  per-mode = symbol,
}

\begin{document}
\begin{table}[h]
\begin{tabularx}{\textwidth}{>{\bfseries}l*{3}{>{\raggedright\arraybackslash}X}}
\toprule
 & \textbf{Fremstilling}
  & \textbf{Brug}
  & \textbf{Bortskaffelse}                                                    \\
\midrule
Materiale & Stål (\SI{9,95}{\kilo\gram})
  & Energiforbrug til mekanisme
  & Energiforbrug til omsmeltning                                             \\
\addlinespace
Energi & \SI{3133,16}{\mega\joule}
  & Nok energi til at tr\ae{}kke \SI{26.2}{\newton} hver gang, at anordningen aktiveres.
  & \SI{846,8}{\mega\joule}                                                   \\
\addlinespace
Kemikalier & -
  & Eventuel sm\o{}relse
  & -                                                                         \\
\addlinespace
Andet & Slibning, eventuel galvanisering (rustfrit)
  & Vedligeholdelse, udskiftning af pigge
  & Genanvendelse af stål (\SI{10}{\mega\joule\per\kilo\gram} til omsmeltning)\\
\bottomrule
\end{tabularx}
\end{table}
\end{document}

enter image description here

I used booktabs for more professional-looking rules and layout, tabularx to set the table as wide as the text and distribute column widths, wrapping text where appropriate, and siunitx for typesetting physical quantities with units.

The \addlinespace commands are optional; I thought the extra space provided helped separate the rows a bit better, but others may have different opinions. Typically, I would use \addlinespace just once or twice in a table to highlight/set off a specific row(s).

  • 1
    The input code features the character ø, but the screenshot seems to show \emptyset; probably not the intended result, right? – Mico Jan 27 '15 at 6:22
  • @Mico thanks for catching that; I thought I had fixed all of those. I'm not used to all these "weird" languages... ;-) – Paul Gessler Jan 27 '15 at 9:40

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.