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.

Ciao guys, I need to make the table below have certain properties To fit onto the page. And then making the columns evenly spaced even if it means breaking up the long column label.

\documentclass[12pt]{article} %
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{tabularx}% http://ctan.org/pkg/tabularx

\begin{document}
\begin{table}[htbp]
  \centering
  \caption{Descriptive statistics of country-level yearly covariates}
    \begin{tabular}{rccc|ccc}
    \addlinespace
    \toprule
          & \multicolumn{3}{c}{Countries experiencing spont. events of disturbance } & \multicolumn{3}{c}{Countries not experiencing spont. events of disturbance } \\
    \midrule
          & Obs   & Mean  & Std Dev. & Obs   & Mean  & Std. Dev \\
                    \hline
    Urban population (percent) & 525   & 32.527 & 13.186 & 273   & 30.994 & 11.883 \\
    GDP per capita (constant, USD, year 2000) & 462   & 643.516 & 700.011 & 270   & 488.737 & 480.186 \\
    Democracy indicator (Binary) & 474   & 0.409 & 0.492 & 242   & 0.178 & 0.383 \\
    Internet penetration (users/100 of population) & 418   & 2.739 & 4.598 & 213   & 2.916 & 5.954 \\
    Cellphone subscribers (users/100 of population) & 524   & 10.857 & 20.657 & 270   & 12.015 & 24.364 \\
    \bottomrule
    \end{tabular}%
  \label{covariates}%
\end{table}%
\end{document}
share|improve this question
add comment

2 Answers

up vote 8 down vote accepted

Here is one way to get the table to fit:

  • Use >{\raggedright}m{3.0cm} for the first column. This make the column a fixed width, and centers the content vertically.
  • Split the header over several rows.
  • I also added \hrule to make the rows stand out.

enter image description here

Code:

\documentclass[12pt]{article} %
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{tabularx}% http://ctan.org/pkg/tabularx

\begin{document}
\begin{table}[htbp]
  \centering
  \caption{Descriptive statistics of country-level yearly covariates}
    \begin{tabular}{>{\raggedright}m{3.0cm}ccc|ccc}
    \addlinespace
    \toprule
          & \multicolumn{3}{c}{Countries experiencing} & \multicolumn{3}{c}{Countries not experiencing} \\
          & \multicolumn{3}{c}{spont. events } & \multicolumn{3}{c}{spont. events} \\
          & \multicolumn{3}{c}{of disturbance } & \multicolumn{3}{c}{of disturbance } \\
    \midrule
          & Obs   & Mean  & Std Dev. & Obs   & Mean  & Std. Dev \\
                    \hline
    Urban population (percent) & 525   & 32.527 & 13.186 & 273   & 30.994 & 11.883 \\\hrule
    GDP per capita (constant, USD, year 2000) & 462   & 643.516 & 700.011 & 270   & 488.737 & 480.186 \\\hrule
    Democracy indicator (Binary) & 474   & 0.409 & 0.492 & 242   & 0.178 & 0.383 \\\hrule
    Internet penetration (users/100 of population) & 418   & 2.739 & 4.598 & 213   & 2.916 & 5.954 \\\hrule
    Cellphone subscribers (users/100 of population) & 524   & 10.857 & 20.657 & 270   & 12.015 & 24.364 \\
    \bottomrule
    \end{tabular}%
  \label{covariates}%
\end{table}%
\end{document}
share|improve this answer
    
Thanks very nice, just one more little thing. Rather than using \hrule, is it possible to increase the spacing between the rows to make them stand out? –  Abhimanyu Arora Jun 8 '12 at 6:54
1  
You can try \renewcommand{\arraystretch}{1.3}. –  Peter Grill Jun 8 '12 at 7:01
1  
Thanks @Peter, I also found a solution; a simple backlash instead of \hline plus a blank line:-) –  Abhimanyu Arora Jun 8 '12 at 7:05
1  
Instead of \hrule, you could also use \cmidrule{1-1}. Doing so will automatically add a nice amount of vertical "breathing space" above and below the rule. –  Mico Jun 8 '12 at 8:13
add comment
\documentclass[12pt]{article} %
\usepackage{tabularx,booktabs}
\usepackage{ragged2e}
\renewcommand\tabularxcolumn[1]{m{#1}}
\begin{document}

\noindent
\begin{tabularx}{\linewidth}{@{}>{\RaggedRight}Xcrr|crr @{}}
    \addlinespace
    \toprule
          & \multicolumn{3}{p{4.75cm}}{\RaggedRight Countries experiencing spont. events of disturbance}
          & \multicolumn{3}{p{5cm}}{\RaggedRight Countries not experiencing spont. events of disturbance } \\
    \midrule
          & Obs   & Mean  & Std Dev. & Obs   & Mean  & Std. Dev \\
                    \hline
    Urban population (percent) & 525   & 32.527 & 13.186 & 273   & 30.994 & 11.883 \\\hrule
    GDP per capita (constant, USD, year 2000) & 462   & 643.516 & 700.011 & 270   & 488.737 & 480.186 \\\hrule
    Democracy indicator (Binary) & 474   & 0.409 & 0.492 & 242   & 0.178 & 0.383 \\\hrule
    Internet penetration (users/100 of population) & 418   & 2.739 & 4.598 & 213   & 2.916 & 5.954 \\\hrule
    Cellphone subscribers (users/100 of population) & 524   & 10.857 & 20.657 & 270   & 12.015 & 24.364 \\
    \bottomrule
    \end{tabularx}%

\end{document}

enter image description here

share|improve this answer
    
:Thanks, mate:-) Cheers –  Abhimanyu Arora Jun 8 '12 at 10:25
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.