如何将表格旋转 90° 并将变量拆分为两行或更多行

如何将表格旋转 90° 并将变量拆分为两行或更多行

我想要创建下表:

\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}

由于第一行很长,我的页面放不下。有没有办法 1) 将表格旋转 90° 并将其放在单独的页面上 2) 将变量(欧洲和中亚等)分成两行(或三行)以减少宽度

答案1

这个布局怎么样?不需要横向布局,我只转动了列标题:

\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} 

在此处输入图片描述

答案2

landscape您可以使用包中的环境来获得横向页面pdflscape。为了在列标题中引入自动换行,我使用了tabularx包。

\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}

在此处输入图片描述

或者,您也可以将表格保留为纵向,并用缩写替换长列标题,如下例所示:

\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}

在此处输入图片描述

答案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}

在此处输入图片描述

相关内容