Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers 3

up vote 4 down vote accepted
\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}

screenshot

share|improve this answer
add comment

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.

Addendum

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.

enter image description here

share|improve this answer
    
Thanks.Can you tell me how to do it longtable also. –  Vinod Feb 18 '11 at 8:30
1  
@Vinod: change tabular to longtable and load package longtable, that's all –  Herbert Feb 18 '11 at 9:12
add comment

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}

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.