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 am creating a table where some cells would contain very long text. For these cases, I want the content of this cell to take up multiple lines. With the default implementation, after building , I see that the contents are truncated. Clearly this isn't what I would like to achieve.

Please find the code below. As you can see, some of the entries for second column is quite big to fit in one row. This is also causing the third column to never appear on PDF file.

\documentclass[twoside,11pt]{article}

\begin{document}

\begin{table}[ht]
\caption{Categories and example of attributes}
\label{atts}
\centering
\begin{tabular}{l l p{8.0cm} l}
\hline
Variable & Items & Category \\
\hline
Built-up area  & Inside built-up area; outside built-up area & !!!CAT!!! \\
Type of road  & Highway; district or province road & !!!CAT!!! \\
Type of road lanes  & Road with one road lane; road with separated road lanes & !!!CAT!!! \\
Intersection  & Near intersection; outside intersection & !!!CAT!!! \\
Location characteristic  & Road works; bridge; tunnel; railroad; roundabout & !!!CAT!!! \\
Road factors  & Bad road surface; faulty signals; faulty lighting; road works; queue; downhill; curve; bad visibility & !!!CAT!!! \\
Miscellaneous  & Accident following accident; aquaplaning; sun blinded; school; recreation centre; bus stop; person swung out of vehicle; no safety belt; no helmet; no child seat; cargo on roadway before accident; cargo on roadway because of accident; fire after accident; comments & !!!CAT!!! \\
Total number of deaths  & 0; 1; 2; 3; 4; 5 & !!!CAT!!! \\ [1ex]
\hline
\end{tabular}
\end{table}

~\ref{atts} is bad.

\end{document}
share|improve this question
    
Use the p{<length>} column type. If that does not solve your problem, please composed a fully compilable MWE including \documentclass and the appropriate packages that illustrates the problem. –  Peter Grill Dec 2 '12 at 8:00
    
@PeterGrill: You mean, something like \begin{tabular}{l p{length50} l} ? –  Shamim Hafiz Dec 2 '12 at 8:13
    
No, I mean something like \begin{tabular}{l p{4.0cm}}. This will make this column be similar to a \parbox{}, which can have multiple line and wrap. The 4.0cm specifies the width of the column. –  Peter Grill Dec 2 '12 at 8:15
    
@PeterGrill It's not working as of now. I have updated question with code. –  Shamim Hafiz Dec 2 '12 at 8:23
    
Are all those lines really required to illustrate the problem? Please try to do some work to reduce the code to just enough to show the root of the problem. –  Peter Grill Dec 2 '12 at 8:27

2 Answers 2

up vote 1 down vote accepted

As Peter Grill mentioned, the code containing the p{}-columntype is working well. As your table is quite long, i created a solution using the longtable-package, which creates the table over several pages. You will need two runs of pdflatex or whatever you use to make this being print correctly. Please containe the documentation of the longtable-package for more information.

\documentclass[twoside,11pt]{article}
\usepackage{longtable}
\begin{document}

\begin{longtable}{p{.25\linewidth}p{.45\linewidth}p{1.5cm}}
\caption{Categories and example of attributes}\label{atts}\\\hline
Variable & Items & Category \\\hline
\endfirsthead
\hline
Variable & Items & Category \\\hline
\endhead
Built-up area  & Inside built-up area; outside built-up area & !!!CAT!!! \\
Type of road  & Highway; district or province road & !!!CAT!!! \\
Type of road lanes  & Road with one road lane; road with separated road     lanes & !!!CAT!!! \\
Intersection  & Near intersection; outside intersection & !!!CAT!!! \\
Intersection traffic regulation  & Intersection police officer; intersection; signalized intersection flashing light; intersection traffic signs; intersection priority to right & !!!CAT!!! \\
Location characteristic  & Road works; bridge; tunnel; railroad; roundabout & !!!CAT!!! \\
Road factors  & Bad road surface; faulty signals; faulty lighting; road works; queue; downhill; curve; bad visibility & !!!CAT!!! \\
Miscellaneous  & Accident following accident; aquaplaning; sun blinded; school; recreation centre; bus stop; person swung out of vehicle; no safety belt; no helmet; no child seat; cargo on roadway before accident; cargo on roadway because of accident; fire after accident; comments & !!!CAT!!! \\
Weather conditions  & Normal weather; rain; fog; wind; snow; hail; other weather & !!!CAT!!! \\
Road conditions  & Road surface: dry; wet; snow; clean; dirty & !!!CAT!!! \\
Light conditions  & Daylight; twilight; public lighting; night & !!!CAT!!! \\
Week  & Week; weekend & !!!CAT!!! \\
Day of week  & Monday; Tuesday; Wednesday; Thursday; Friday; Saturday; Sunday & !!!CAT!!! \\
Part of the day  & Morning rush hour (7-–9 a.m.); morning (10-–12 a.m.); afternoon (1-–3 p.m.); evening rush hour (4-–6 p.m.); evening (7-–9 p.m.); night (10-–6 a.m.) & !!!CAT!!! \\
Type of road user  & Car; car double use; minibus; light truck; camper; truck; truck and trailer; truck; tractor; bus; trolleybus; motor coach; motorbike under 400 cm3; motorbike over 400 cm 3; moped A; moped B; moped three to four wheels; bike; span; wheel chair; pedestrian with bike; pedestrian; horseman; other road user & !!!CAT!!! \\
Direction  & Positive way; negative way; transverse way; way not applicable & !!!CAT!!! \\
Movement  & Straight direction; opposite direction; loss control to the left; loss control to the right; left turn; right turn; pass left; pass right; u-turn; drive backwards; car breakdown; standstill opening door; standstill; parking; private property; other movement & !!!CAT!!! \\
Dynamics  & Constant speed; brake; accelerate; standstill & !!!CAT!!! \\
Alcohol  & No alcohol test; refused alcohol test; positive alcohol test; negative alcohol test & !!!CAT!!! \\
Sex road user  & Male road user; female road user & !!!CAT!!! \\
Consequences road user  & Dead road user; seriously injured road user; lightly injured road user; uninjured road user & !!!CAT!!! \\
Age road user  & Age road user 0–-17; 18–-29; 30-–45; 46-–60; over 60 & !!!CAT!!! \\
Condition road user  & Road user in normal condition; drunken road user; sedated road user; ill road user & !!!CAT!!! \\
Factors road user  & Through red light; no priority, over white line; incorrect passing; sidestep maneuver; incorrect position on roadway; loss control steering wheel; no distance; fall & !!!CAT!!! \\
Factors vehicle  & Incorrect vehicle lights; bad tires; flat tire; defect trailer or cargo & !!!CAT!!! \\
Type of collision  & Multiple collision; frontal collision; parallel collision; sideways collision; pedestrian collision; collision obstacle on roadway; collision obstacle outside roadway; collision no obstacle & !!!CAT!!! \\
Type of obstacle  & Animal; train; streetcar; load on roadway; container; road works; street border; speed ramp; excavation; tree; public lighting; post; over crash barrier; against crash barrier; wall; fence; canal; other obstacle & !!!CAT!!! \\
Position pedestrian  & On footpath; pedestrian on cycle track; pedestrian out of vehicle; pedestrian right side roadway; pedestrian left side roadway; zebra crossing with traffic lights; zebra crossing with police officer; zebra crossing; next to zebra crossing with traffic lights; next to zebra crossing with police officer next to zebra crossing; no zebra crossing; pedestrian not moving on roadway & !!!CAT!!! \\
Visibility pedestrian  & Pedestrian visible; pedestrian not visible & !!!CAT!!! \\
Walking distance pedestrian  & Walking distance 1–4 m; walking distance 5–10 m; walking distance 11–15 m; walking distance over 16 m & !!!CAT!!! \\
Position cyclist  & Separated cycle track; marked cycle track on roadway; other cycle track & !!!CAT!!! \\
Cycle track  & One way cycle track; two way cycle track normal direction; one way cycle track opposite direction & !!!CAT!!! \\
Gender passenger  & Male passenger; female passenger & !!!CAT!!! \\
Consequences passenger  & Dead passenger; seriously injured passenger; lightly injured passenger & !!!CAT!!! \\
Position passenger  & Passenger front seat; passenger back seat & !!!CAT!!! \\
Age passenger  & 0–-17; 18–-29; 30-–45; 46-–60; over 60 years old & !!!CAT!!! \\
Gender victim  & male victim; female victim & !!!CAT!!! \\
Age victim  & 0–-17; 18–-29; 30–-45; 46-–60; over 60 years old & !!!CAT!!! \\
Consequences victim  & Dead; seriously injured; lightly injured & !!!CAT!!! \\
Number of road users  & 0; 1; 2; 3; 4; 5; 6; 7; 8 & !!!CAT!!! \\
Number of passengers  & 0; 1; 2; 3; 4; 5  & !!!CAT!!! \\
Number of victims  & 0; 1; 2; 3; 4; 5  & !!!CAT!!! \\
Total number of lightly injured  & 0; 1; 2; 3; 4; 5; 6; 7 & !!!CAT!!! \\
Total number of seriously injured  & 0; 1; 2; 3; 4; 5 & !!!CAT!!! \\
Total number of deaths  & 0; 1; 2; 3; 4; 5 & !!!CAT!!! \\ [1ex]\hline
\end{longtable}

\end{document}
share|improve this answer
    
This seems to be working with at my end. Though I would need to fiddle a little with the width parameters to make things look better. –  Shamim Hafiz Dec 2 '12 at 8:57
    
Could you please take a look at tex.stackexchange.com/q/85173/18913 which refers to the same set of code. –  Shamim Hafiz Dec 2 '12 at 9:04
    
I just tried out some width parameters that actually worked. You are right, it needs more fine tuning, depending on the result, you want to achieve. I hope Uwe Ziegenhagen's answer in your related question is fine for you, so I won't post another answer there. –  Stephan Lukasczyk Dec 2 '12 at 10:16

Using {l p{8.0cm} l} seems to work:

enter image description here

Notes:

  • You should consider using the tabularx package pacakge so that you can eaily take up the fill \linewidth available on the page.
  • Also you should have a look at the booktabs package for more professional looking tables.

Code:

\documentclass[twoside,11pt]{article}

\begin{document}

\begin{table}[ht]
\caption{Categories and example of attributes}
\label{atts}
\centering
\begin{tabular}{l p{8.0cm} l}
\hline
Variable & Items & Category \\
\hline
Built-up area  & Inside built-up area; outside built-up area & !!!CAT!!! \\
Type of road  & Highway; district or province road & !!!CAT!!! \\
Type of road lanes  & Road with one road lane; road with separated road lanes & !!!CAT!!! \\
Intersection  & Near intersection; outside intersection & !!!CAT!!! \\
Location characteristic  & Road works; bridge; tunnel; railroad; roundabout & !!!CAT!!! \\
Road factors  & Bad road surface; faulty signals; faulty lighting; road works; queue; downhill; curve; bad visibility & !!!CAT!!! \\
Miscellaneous  & Accident following accident; aquaplaning; sun blinded; school; recreation centre; bus stop; person swung out of vehicle; no safety belt; no helmet; no child seat; cargo on roadway before accident; cargo on roadway because of accident; fire after accident; comments & !!!CAT!!! \\
Total number of deaths  & 0; 1; 2; 3; 4; 5 & !!!CAT!!! \\ [1ex]
\hline
\end{tabular}
\end{table}

~\ref{atts} is bad.

\end{document}
share|improve this answer
    
Which setup of Latex are you using? I am wondering if the problem lies in that.. –  Shamim Hafiz Dec 2 '12 at 8:40
    
I am TeXLive2012, but I seriously doubt this is an issue of you having an older version. But still would recommend you upgrade to the current release in case you are on some older release (2009??). –  Peter Grill Dec 2 '12 at 8:42
    
I am on MikTex and Texmaker collection. –  Shamim Hafiz Dec 2 '12 at 8:44

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.