1

I want to create the following table:

\begin{table}
        \centering
        \begin{tabular}
            {l c c c}
            \toprule
            Advanced Economies & Europe and Central Asia & East Asia and the Pacific & South Asia & Middle East and North Africa & Sub-Saharan Africa & Latin America and the Caribbean \\
            \midrule
            e & 7 & 8 & 9 & 7 & 8 & 9\\
            d & 7 & 8 & 9 & 7 & 8 & 9\\
            f & 7 & 8 & 9 & 7 & 8 & 9\\
            \bottomrule
        \end{tabular}
        \caption{Availability of indicators for different country groups}
        \label{tab:regions}
    \end{table}

Since the first line is very long, it doesn't fit on my page. Is there a way to 1) turn the table by 90° and put it on a separate page 2) split the variables (Europe and Central Asia etc.) into two (or three) lines to reduce it in width

New contributor
Diramel is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • 1
    Could you please make your example code compilable by adding the documentclass as well as the relevant packages? Also, you use 7 columns, but only define 4. – leandriis Jun 12 at 20:05
7

How about this layout? No landscape required, I only turned the column heads:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx, rotating} 
\usepackage{multirow,bigstrut, makecell, booktabs}
\usepackage{setspace} 
\usepackage{amsmath}
\renewcommand{\arraystretch}{1.5}
\renewcommand{\cellset}{\renewcommand{\arraystretch}{1.25}}
\newcommand{\myrotcell}[2][2.9cm]{\rotcell{\rlap{\setstretch{0.8}\parbox[b]{#1}{\small\raggedright#2}}}}
\usepackage{geometry}

\begin{document}

    \begin{table}
            \centering
            \setlength{\rotheadsize}{1cm}
            \renewcommand{\cellrotangle}{45}
            \setlength{\cmidrulewidth}{0.08em }
    \begin{tabular}{*{7}{l}}
                \cmidrule(lr{-2em}){1-7}
                \addlinespace[5.5ex]
              \makecell{Advanced\\[-1ex] Economies} & \myrotcell{Europe and\\ Central Asia} &\myrotcell{East Asia and\\ the Pacific} & \hspace*{-1em} \myrotcell{South Asia}& \myrotcell{Middle East~and North Africa} & \myrotcell{Sub-Saharian Africa} & \myrotcell{Latin America and\\ the Caribbean} \\[-1ex]
                \cmidrule[0.05em](lr{-2em}){1-7}
                e & 7 & 8 & 9 & 7 & 8 & 9\\
                d & 7 & 8 & 9 & 7 & 8 & 9\\
                f & 7 & 8 & 9 & 7 & 8 & 9\\
                \cmidrule(lr{-2em}){1-7}
    \end{tabular}
    \caption{Availability of indicators for different country groups}
    \label{tab:regions}
\end{table}

\end{document} 

enter image description here

  • that looks great, thank you! – Diramel Jun 13 at 12:01
4

You can get a landscape oriented page by using the landscape environment from the pdflscape package. In order to introduce automatic linebreaks in the column headers, I have used the tabularx package.

\documentclass{article}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{ragged2e}
\usepackage{pdflscape}
\begin{document}
\begin{landscape}
\begin{table}
        \centering
        \begin{tabularx}{\linewidth}
            {*{7}{>{\Centering}X}}
            \toprule
            Advanced Economies & Europe and Central Asia & East Asia and the Pacific & South Asia & Middle East and North Africa & Sub-Saharan Africa & Latin America and the Caribbean \\
            \midrule
            e & 7 & 8 & 9 & 7 & 8 & 9\\
            d & 7 & 8 & 9 & 7 & 8 & 9\\
            f & 7 & 8 & 9 & 7 & 8 & 9\\
            \bottomrule
        \end{tabularx}
        \caption{Availability of indicators for different country groups}
        \label{tab:regions}
    \end{table}
\end{landscape}
\end{document}

enter image description here

Alternatively, you could also leave the table in portrait orientation and replace the long column headers by abbreviations as shown in the following example:

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{table}
        \centering
        \begin{tabular}
            {lcccccc}
            \toprule
            Advanced Economies & ECA & EAP & SA & MENA & SSA & LAC \\
            \midrule
            e & 7 & 8 & 9 & 7 & 8 & 9\\
            d & 7 & 8 & 9 & 7 & 8 & 9\\
            f & 7 & 8 & 9 & 7 & 8 & 9\\
            \midrule
            \multicolumn{7}{p{10.25cm}}{ECA~= Europe and Central Asia, EAP~= East Asia and the Pacific, SA~= South Asia MENA~= Middle East and North Africa, SSA~= Sub-Saharan Africa, LAC~=Latin America and the Caribbean}\\
        \end{tabular}
        \caption{Availability of indicators for different country groups}
        \label{tab:regions}
    \end{table}
\end{document}

enter image description here

  • The second option is even better. Thank you! – Diramel Jun 12 at 20:23
3
\documentclass[a4paper]{article}

\usepackage{microtype}

\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{varwidth}

\usepackage{graphicx}

\newsavebox\mytempbox

\newcolumntype{Y}{%
  >{\centering
    \begin{varwidth}[t]{\hsize}%
    \narrowragged
    \hyphenpenalty=50
    \exhyphenpenalty=50
    \doublehyphendemerits=50
    \arraybackslash
    \hspace{0pt}%
   }X<{\end{varwidth}}%
}%

\newcolumntype{Z}{%
  >{\raggedright
    \begin{varwidth}[t]{\hsize}%
    \narrowragged
    \hyphenpenalty=50
    \exhyphenpenalty=50
    \doublehyphendemerits=50
    \arraybackslash
    \hspace{0pt}%
   }X<{\end{varwidth}}%
}%    

%\hyphenation{...}%

\begin{document}

\noindent Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text

\savebox{\mytempbox}{%
    \begin{tabularx}{\textwidth}{l*{6}{c}}
        \toprule
        \multicolumn{1}{Z}{Ad\-vanced Econ\-o\-mies\strut}&
        \multicolumn{1}{Y}{Eu\-rope and Cen\-tral Asia\strut}&
        \multicolumn{1}{Y}{East Asia and the Pa\-cif\-ic\strut}&
        \multicolumn{1}{Y}{South Asia\strut}&
        \multicolumn{1}{Y}{Mid\-dle East and North Af\-ri\-ca\strut}&
        \multicolumn{1}{Y}{Sub-Sa\-ha\-ran Af\-ri\-ca\strut}&
        \multicolumn{1}{Y}{Latin Amer\-ica and the Car\-ib\-bean\strut}\\
        \midrule
        e & 7 & 8 & 9 & 7 & 8 & 9\\
        d & 7 & 8 & 9 & 7 & 8 & 9\\
        f & 7 & 8 & 9 & 7 & 8 & 9\\
        \bottomrule
    \end{tabularx}%
}%

\begin{table}%
  \centering
  \begin{minipage}{\wd\mytempbox}%
  \usebox{\mytempbox}%
  \caption{Availability of indicators for different country groups}%
  \label{tab:regions1}%
  \end{minipage}%
\end{table}

\savebox{\mytempbox}{%
    \begin{tabularx}{.45\textheight}{l*{6}{c}}
        \toprule
        \multicolumn{1}{Z}{Ad\-vanced Econ\-o\-mies\strut}&
        \multicolumn{1}{Y}{Eu\-rope and Cen\-tral Asia\strut}&
        \multicolumn{1}{Y}{East Asia and the Pa\-cif\-ic\strut}&
        \multicolumn{1}{Y}{South Asia\strut}&
        \multicolumn{1}{Y}{Mid\-dle East and North Af\-ri\-ca\strut}&
        \multicolumn{1}{Y}{Sub-Sa\-ha\-ran Af\-ri\-ca\strut}&
        \multicolumn{1}{Y}{Latin Amer\-ica and the Car\-ib\-bean\strut}\\
        \midrule
        e & 7 & 8 & 9 & 7 & 8 & 9\\
        d & 7 & 8 & 9 & 7 & 8 & 9\\
        f & 7 & 8 & 9 & 7 & 8 & 9\\
        \bottomrule
    \end{tabularx}%
}%

\begin{table}%
\rotatebox[origin=C]{270}{%
  \centering
  \begin{minipage}{\wd\mytempbox}%
  \usebox{\mytempbox}%
  \caption{Availability of indicators for different country groups}%
  \label{tab:regions2}%
  \end{minipage}%
}%
\hfill
\rotatebox[origin=C]{90}{%
  \centering
  \begin{minipage}{\wd\mytempbox}%
  \usebox{\mytempbox}%
  \caption{Availability of indicators for different country groups}%
  \label{tab:regions3}%
  \end{minipage}%
}%
\end{table}

\end{document}

enter image description here

Your Answer

Diramel is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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