General ⇒ multiple line cell
-
- Posts: 3
- Joined: Tue Aug 05, 2008 5:03 pm
multiple line cell
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.
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- Stefan Kottwitz
- Site Admin
- Posts: 10360
- Joined: Mon Mar 10, 2008 9:44 pm
multiple line cell
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
-
- Posts: 3
- Joined: Tue Aug 05, 2008 5:03 pm
Re: multiple line cell
\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: 10360
- Joined: Mon Mar 10, 2008 9:44 pm
multiple line cell
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
multiple line cell
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.