# How to set the width of the cell and allow it to take multiple lines?

I have a table below

\documentclass[a4paper,12pt]{article}
\begin{document}
\begin{quote}
\begin{tabular}{|c|c|c|c|c|}
\hline
\multicolumn{4}{c}{Table title}\\
\hline
Fuze Type & Weight & Muzzle Velocity & From sea level\\
\hline
Time & Vehicle wt: 5000

Tyre wt: 100&40000 m/s & 0m\\
\hline
Degrees & Minutes & Mil &Range in m & Time of flight in s\\
\hline
\end{tabular}
\end{document}

1. I want the second column to be of fixed width and if the length of text in this column is more, text will be allowed to take multiple lines without changing the width. Edit:Can you also tell me how to do the same in longtable.(|>{\centering}p{2cm}| doesn't seem to work in longtable.

2. I want left and right edges of the top row visible.

3. I need the last columns of rows 2 and 3 invisible(no borders), since there is no data in those cells.

-

\documentclass[a4paper,12pt]{article}
\begin{document}
\begin{quote}
\begin{tabular}{|c|p{3cm}|c|c|c|}
\cline{1-4}
\multicolumn{4}{|c|}{Table title}\\
\cline{1-4}
Fuze Type & Weight & Muzzle Velocity & From sea level\\
\cline{1-4}
\centering
Time & Vehicle wt: 5000

Tyre wt: 100&40000 m/s & 0m\\
\hline
Degrees & Minutes & Mil &Range in m & Time of flight in s\\
\hline
\end{tabular}
\end{quote}
\end{document}


-

To get a column that wraps, you need to use the p column type. To make that column be centred, you need to use the array package. To get the vertical lines on empty cells you need to put the column separator & to mark the cells, not simply end a row with \\.

\documentclass[a4paper,12pt]{article}
\usepackage{array}
\begin{document}
\begin{tabular}{|c|>{\centering}p{2cm}|c|c|c|}
\hline
\multicolumn{5}{|c|}{Table title} \\
\hline
Fuze Type & Weight & Muzzle Velocity & From sea level &\\
\hline
Time & Vehicle wt: 5000

Tyre wt: 100&40000 m/s & 0m &\\
\hline
Degrees & Minutes & Mil &Range in m & Time of flight in s\\
\hline
\end{tabular}
\bigskip

\begin{tabular}{|c|>{\centering}p{2cm}|c|c|c|}
\cline{1-4}
\multicolumn{4}{|c|}{Table title} \\
\cline{1-4}
Fuze Type & Weight & Muzzle Velocity & From sea level \\
\cline{1-4}
Time & Vehicle wt: 5000

Tyre wt: 100&40000 m/s & 0m \\
\hline
Degrees & Minutes & Mil &Range in m & Time of flight in s\\
\hline
\end{tabular}

\end{document}


Normally the title would be a caption to the table, rather than a row in itself. You can do this by wrapping the whole tabular in a table environment, and adding a \caption{Title} command.

Many people think that vertical lines in tables are not good form; take a look a the booktabs package for very nice looking tables without vertical lines.

Sorry I didn't read your request as carefully, since the resultant table looks quite odd. But I've added a second table matching your actual request.

-
Thanks.Can you tell me how to do it longtable also. –  Vinod Feb 18 '11 at 8:30
@Vinod: change tabular to longtable and load package longtable, that's all –  Herbert Feb 18 '11 at 9:12

choose a greater baselineskip, makes the table looks nicer:

\documentclass[a4paper,12pt]{article}
\begin{document}

{\renewcommand\arraystretch{1.8}
\begin{tabular}{|c|p{3cm}|c|c|c}\cline{1-4}
\multicolumn{4}{|c|}{Table title}\\\cline{1-4}
Fuze Type & Weight & Muzzle Velocity & From sea level\\\cline{1-4}
Time & Vehicle wt: 5000
Tyre wt: 100&40000 m/s & 0m\\\hline
Degrees & Minutes & Mil &Range in m
& \multicolumn{1}{c|}{Time of flight in s}\\\hline
\end{tabular}}

\end{document}


-