Hi,
How can I create a table with cells that have several lines? So far, whenever I enter text in a cell, the text fits in a line - but there's always a hbox error.
I tried \linebreak but it's not working.
Thanks.
General ⇒ multiple line cell
NEW: TikZ book now 40% off at Amazon.com for a short time.

- Stefan Kottwitz
- Site Admin
- Posts: 10345
- Joined: Mon Mar 10, 2008 9:44 pm
multiple line cell
Hi,
you could use p columns, try this small example:
The array package provides more features, also regarding multiline cells.
Stefan
you could use p columns, try this small example:
Code: Select all
\documentclass[a4paper,12pt]{article}
\begin{document}
\begin{tabular}{lp{0.75cm}}
1 & long text \\
\hline
2 & text
\end{tabular}
\end{document}
Stefan
LaTeX.org admin
-
- Posts: 3
- Joined: Tue Aug 05, 2008 5:03 pm
Re: multiple line cell
Not working: I tried this:
\begin{tabular}{lp{2in}}
\hline
\bf Power Station & & \bf 2001 & \bf 2002 & \bf 2003 & \bf 2004 & \bf 2005 \rm \\ %there's a empty cell between ' & &'
\hline
Existing Villa Hydropower & MWh & 28570000 & 20283000 & 36083700 & 36854200 & 37103900\\
\hline
Diesel Engine ``TV2'' & MWh & 143700 & 310300 & 80800 & 20900 &\\\hline
Diesel Engine ``TV3'' & MWh & 24175000 & 30067000 & 14850000 & 16007000 & 19679000\\\hline
Diesel Engine ``Private Fraise'' & MWh & & 741450 & 6354050 & 8041850 & 5349350\\\hline
Total & & \bf 52888700 & \bf 51401750 & \bf 57268550 & \bf 60923950 & \bf 62132250\\
\end{tabular}
Here is my error log:
! Extra alignment tab has been changed to \cr.
I have no idea what's going on.
\begin{tabular}{lp{2in}}
\hline
\bf Power Station & & \bf 2001 & \bf 2002 & \bf 2003 & \bf 2004 & \bf 2005 \rm \\ %there's a empty cell between ' & &'
\hline
Existing Villa Hydropower & MWh & 28570000 & 20283000 & 36083700 & 36854200 & 37103900\\
\hline
Diesel Engine ``TV2'' & MWh & 143700 & 310300 & 80800 & 20900 &\\\hline
Diesel Engine ``TV3'' & MWh & 24175000 & 30067000 & 14850000 & 16007000 & 19679000\\\hline
Diesel Engine ``Private Fraise'' & MWh & & 741450 & 6354050 & 8041850 & 5349350\\\hline
Total & & \bf 52888700 & \bf 51401750 & \bf 57268550 & \bf 60923950 & \bf 62132250\\
\end{tabular}
Here is my error log:
! Extra alignment tab has been changed to \cr.
I have no idea what's going on.
- Stefan Kottwitz
- Site Admin
- Posts: 10345
- Joined: Mon Mar 10, 2008 9:44 pm
multiple line cell
You declared only 2 columns. Try this modified example:
though the tabular layout may still need some improvement.
Stefan
Code: Select all
\documentclass[a4paper,10pt]{article}
\usepackage[hmargin={1in,1in}]{geometry}
\begin{document}
\begin{tabular}{p{1in}rrrrrr}
\hline
\textbf{Power Station} & & \textbf{2001} & \textbf{2002} &
\textbf{2003} & \textbf{2004} & \textbf{2005} \\ %there's a empty cell between ' & &'
\hline
Existing Villa Hydropower & MWh & 28570000 & 20283000 & 36083700 & 36854200 & 37103900\\
\hline
Diesel Engine ``TV2'' & MWh & 143700 & 310300 & 80800 & 20900 &\\\hline
Diesel Engine ``TV3'' & MWh & 24175000 & 30067000 & 14850000 & 16007000 & 19679000\\\hline
Diesel Engine ``Private Fraise'' & MWh & & 741450 & 6354050 & 8041850 & 5349350\\\hline
Total & & \bf 52888700 & \bf 51401750 & \bf 57268550 & \bf 60923950 & \bf 62132250\\
\end{tabular}
\end{document}
Stefan
LaTeX.org admin
multiple line cell
Hi,
you are trying to create a seven column table but you only declare two columns in the table format.
In the code below I made some modifications to your table using some features provided by the array and booktabs packages. Refer to the packages documentation for further information.
Remarks: 1) I enclosed the tabular environment to keep some changes (such as the font size) local.
2) I suggest you not to use obsolete commands such as \bf (use \bfseries instead). The reasons and more useful information can be found in l2tabu.
3) Basic information about tables can be found here:
Getting to grips with LaTeX - Tables.
4) The table still admits improvements.
you are trying to create a seven column table but you only declare two columns in the table format.
In the code below I made some modifications to your table using some features provided by the array and booktabs packages. Refer to the packages documentation for further information.
Code: Select all
\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\begin{document}
\begingroup
\setlength\tabcolsep{3pt}
\small
\begin{tabular}{b{1in}crrrrr}
\toprule
{\bfseries Power Station} & & {\bfseries 2001} & {\bfseries 2002} & {\bfseries 2003} & {\bfseries 2004} & {\bfseries 2005} \\
\midrule
Existing Villa\newline Hydropower & MWh & 28570000 & 20283000 & 36083700 & 36854200 & 37103900\\
\midrule
Diesel Engine\newline ``TV2'' & MWh & 143700 & 310300 & 80800 & 20900 &\\\midrule
Diesel Engine\newline ``TV3'' & MWh & 24175000 & 30067000 & 14850000 & 16007000 & 19679000\\\midrule
Diesel Engine\newline ``Private Fraise'' & MWh & & 741450 & 6354050 & 8041850 & 5349350\\\midrule
Total & & {\bfseries 52888700} & {\bfseries 51401750} & {\bfseries 57268550} & {\bfseries 60923950} & {\bfseries 62132250}\\
\end{tabular}
\endgroup
\end{document}
2) I suggest you not to use obsolete commands such as \bf (use \bfseries instead). The reasons and more useful information can be found in l2tabu.
3) Basic information about tables can be found here:
Getting to grips with LaTeX - Tables.
4) The table still admits improvements.
1,1,2,3,5,8,13,21,34,55,89,144,233,...