3

This question already has an answer here:

The table produced by this code always goes out off the width of my page. I want the table to fit within the width of the page. I tried giving extra \\ in between but it made it worse only.

\begin{tabular}{|l|l|}
\hline 
 LocationProvider & Description \\ 
 \hline 
 network & Uses the mobile network or WI-Fi to determine the best location.Might have a higher precision in closed rooms than GPS. \\
\hline 
gps & Use the GPS receiver in the Android device to determine the best location via satellites. Usually better precision than network. \\
\hline 
passive & Allows to participate in location of updates of other components to save energy \\ 
\hline 
\end{tabular}

The result: enter image description here

marked as duplicate by Werner formatting Jan 16 '18 at 1:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Use '|p{<width 1>}|p{<width 2>}|' instead of '|l|l|'. – user10274 May 12 '13 at 11:21
  • Thanks alot @MarcvanDongen.. It worked awesomely and beautifully.. :) :) I am exaggerating coz I was stuck on it for half an hour... – Raptor May 12 '13 at 11:28
3

"l" means left aligned so everything in the cell comes out in a single row and if you have a lot of material you end up exceeding the available width on your page.

Alternatives:

  • use p{<width>} on one or more columns to have the text inside wrap the the specified <width>
  • or use the package tabularx which allows you to get the column width for wrapping columns be determined automatically (see package documentation how to do this)
  • in some cases using a slightly smaller font for the table might be a choice, but in general I would not recommend this.
  • Thanks @FrankMittelbach.. i used p{<width>} and it worked fine for me.. thanks for letting me know the other alternatives too. :) – Raptor May 12 '13 at 11:33
4

It looks like a job for package tabularx:

\documentclass{article}
\usepackage{tabularx}

\begin{document}
\noindent
\begin{tabularx}{\linewidth}{|l|X|}
\hline
 LocationProvider & Description \\
 \hline
 network & Uses the mobile network or WI-Fi to determine the best
 location.Might have a higher precision in closed rooms than GPS. \\
\hline
gps & Use the GPS receiver in the Android device to determine the best
location via satellites. Usually better precision than network. \\
\hline
passive & Allows to participate in location of updates of other components
to save energy \\
\hline
\end{tabularx}
\end{document}

Result

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