Graphics, Figures & TablesTable too wide

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
pointeddot
Posts: 11
Joined: Thu Jun 27, 2013 1:16 am

Table too wide

Post by pointeddot »

Hey guys,

it would be great if anyone here could help me..
This is the table I want to create. Also there are multicolumns and raiseboxes in it. Somehow this table is too wide.

Thank you very much!

Code: Select all

\begin{table}[t]
\begin{center}
\begin{tabular}{|p{1.5cm}| p{1.3cm} | p{2.4cm} | p{2.4cm} | p{2.2cm} | p{1.2cm}|} \hline

\multicolumn{2}{|c|}{} & \multicolumn{2}{|c|}{\textbf{Konventionelle Antriebe [\euro /l]}} & \multicolumn{2}{|c|}{\textbf{Strompreis für Haushalte [ct/kWh]}} \\ \cline{3-6}
\multicolumn{2}{|c|}{\raisebox{1.5ex}[-1.5ex]{2020}} & \textbf{2011} & \textbf{2020} & \textbf{2011} & \textbf{2020} \\ \hline
 & Benzin & 1,55 & 1,65 &  &  \\ \cline{2-4}
 \raisebox{1.5ex}[-1.5ex]{Mittel} & Diesel & 1,42 & 1,58 & \raisebox{1.5ex}[-1.5ex]{25,9} & \raisebox{1.5ex}[-1.5ex]{29} \\ \hline

 & Benzin & 1,55 & 1,78 &  &  \\ \cline{2-4}
 \raisebox{1.5ex}[-1.5ex]{Pro-EV} & Diesel & 1,42 & 1,73 & \raisebox{1.5ex}[-1.5ex]{25,9} & \raisebox{1.5ex}[-1.5ex]{29-DSM} \\ \hline
 
 & Benzin & 1,55 & 1,53 &  &  \\ \cline{2-4}
 \raisebox{1.5ex}[-1.5ex]{Pro-EV} & Diesel & 1,42 & 1,43 & \raisebox{1.5ex}[-1.5ex]{25,9} & \raisebox{1.5ex}[-1.5ex]{33} \\ \hline

\end{tabular}
\end{center}
\caption{Kraftstoff- und Strompreisentwicklung in den drei Szenarien für das Jahr 2020}\label{tab:6}
\end{table}
Last edited by Stefan Kottwitz on Sun Jun 29, 2014 11:14 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Table too wide

Post by Stefan Kottwitz »

There's no automatic line breaking in c columns, and you made the multi columns with c. You could make p there as well. A quick change of the header:

Code: Select all

\begin{tabular}{|p{1.5cm}| p{1.3cm} | p{1.5cm} | p{1.5cm} | p{1.5cm} | p{1.5cm}|} \hline
\multicolumn{2}{|c|}{} & \multicolumn{2}{|p{3.5cm}|}{\centering\textbf{Konventionelle Antriebe [\euro /l]}} & \multicolumn{2}{||p{4cm}||}{\centering\textbf{Strompreis für Haushalte [ct/kWh]}} \\ \cline{3-6}
...
The tabular design could be much better. Since I see that you are writing in German, you could post your table in our German partner forum TeXwelt.de, I'm 100% sure that you will get very good design recommendations and support from our friends there.

Stefan
LaTeX.org admin
pointeddot
Posts: 11
Joined: Thu Jun 27, 2013 1:16 am

Table too wide

Post by pointeddot »

Thanks a lot, it works!

One last question: How can I center the writings in my cells? I tried with m{2cm}, but it did not work.
Thank you!

Code: Select all

\begin{table}[t]
\begin{center}
\begin{tabular}{|p{1.5cm}| p{1.3cm} | p{2.4cm} | p{2.4cm} | p{2.2cm} | p{2.2cm}|} \hline

\multicolumn{2}{|c|}{} & \multicolumn{2}{p{3.5cm}|}{\textbf{Konventionelle Antriebe [\euro /l]}} & \multicolumn{2}{p{3.5cm}|}{\textbf{Strompreis für Haushalte [ct/kWh]}} \\ \cline{3-6}
\multicolumn{2}{|p{3.5cm}|}{\raisebox{1.5ex}[-1.5ex]{}} & \textbf{2011} & \textbf{2020} & \textbf{2011} & \textbf{2020} \\ \hline
 & Benzin & 1,55 & 1,65 &  &  \\ \cline{2-4}
 \raisebox{1.5ex}[-1.5ex]{Mittel} & Diesel & 1,42 & 1,58 & \raisebox{1.5ex}[-1.5ex]{25,9} & \raisebox{1.5ex}[-1.5ex]{29} \\ \hline

 & Benzin & 1,55 & 1,78 &  &  \\ \cline{2-4}
 \raisebox{1.5ex}[-1.5ex]{Pro-EV} & Diesel & 1,42 & 1,73 & \raisebox{1.5ex}[-1.5ex]{25,9} & \raisebox{1.5ex}[-1.5ex]{29-DSM} \\ \hline
 
 & Benzin & 1,55 & 1,53 &  &  \\ \cline{2-4}
 \raisebox{1.5ex}[-1.5ex]{Pro-EV} & Diesel & 1,42 & 1,43 & \raisebox{1.5ex}[-1.5ex]{25,9} & \raisebox{1.5ex}[-1.5ex]{33} \\ \hline

\end{tabular}
\end{center}
\caption{Kraftstoff- und Strompreisentwicklung in den drei Szenarien für das Jahr 2020}\label{tab:6}
\end{table}
Last edited by Stefan Kottwitz on Mon Jun 30, 2014 12:47 am, edited 1 time in total.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Table too wide

Post by Stefan Kottwitz »

m should be used in all column then, not in just one. Have a look at Wie kann ich innerhalb einer Tabellenzelle vertikal zentrieren.

And better use \centering after beginning table, not \begin{center} and \end{center}, which causes additional space.

Btw. framing all table cells is unusual in good books, which tend to use just some horizontal lines for structure to ease reading, not a complete grid. Good books and journals show good examples.

Stefan
LaTeX.org admin
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Table too wide

Post by Johannes_B »

As Stefan already mentioned, the table looks pretty cluttered.

Code: Select all

\documentclass[12pt]{article}
\usepackage[ngerman]{babel}
\usepackage{fontspec}
\setmainfont{Linux Libertine O}
\newcommand\euro{€}
\usepackage{showframe}
\usepackage{booktabs}
\begin{document}

\begin{table}
	\centering
\caption{Kraftstoff- und Strompreisentwicklung in den drei Szenarien für das Jahr 2020}\label{tab:6}
%JB: Table captions usually go on top of the table
\begin{tabular}{cccccc} 
	\toprule
&& \multicolumn{2}{p{3.8cm}}{{Konventionelle Antriebe [\euro /l]}} 
 & \multicolumn{2}{p{3.8cm}}{{Strompreis für Haushalte [ct/kWh]}} \\
 \cmidrule(lr){3-4} \cmidrule(lr){5-6}
& & {2011} & {2020} & {2011} & {2020} \\ 
\midrule
{Mittel} & Benzin & 1,55 & 1,65 &  &  \\ 
 & Diesel & 1,42 & 1,58 &{25,9} & {29} \\ 
\addlinespace
{Pro-EV} & Benzin & 1,55 & 1,78 &  &  \\ 
 & Diesel & 1,42 & 1,73 & {25,9} & {29-DSM} \\ 
\addlinespace 
{Pro-EV} & Benzin & 1,55 & 1,53 &  &  \\ 
 & Diesel & 1,42 & 1,43 & {25,9} & {33} \\ 
\bottomrule
\end{tabular}
\end{table}
\end{document}


BTW: Have a look at the booktabs documentation. There are some good examples on typesetting tables.
Furthermore, you can use package siunitx to typeset values and their units Wie schreibe ich Zahlen mit Einheiten richtig?.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply