在表格的行中定位文本

在表格的行中定位文本

我使用以下代码在我的演示文稿中放置表格

\begin{frame}
\frametitle{Economic theory vs. Socionomic Theory}
\begin{table}
\begin{tabular}{l l}
\toprule
\textbf{Economic voting} & \textbf{Socionomic voting} \\
\midrule
1. Rising markets make \\ investors optimistic & Optimistic investors \\ make markets rise \\
2. Recessions result in  \\ more cautious business practices & More cautious business practices result in recessions \\
3. Scandals outrage \\ public & Outraged public seeks scandals \\
\bottomrule
\end{tabular}
\caption{Table caption}
\end{table}
\end{frame}

问题是,我希望前两行位于第一列下,后两行位于第二列下 - 社会经济理论。您能否给我提示一下,在这种情况下我应该使用哪个命令或符号?

答案1

像这样吗?

在此处输入图片描述

\documentclass{beamer}
\usepackage{booktabs,tabularx,ragged2e}
\newcolumntype{L}{>{\RaggedRight\arraybackslash}X}
\begin{document}
\begin{frame}[t] %% am using '[t]' just for this example
\frametitle{Economic Theory vs.\ Socionomic Theory}
\begin{table}
\setlength\tabcolsep{3pt} % default value: 6pt
\begin{tabularx}{\textwidth}{@{}lLL@{}}
\toprule
& \textbf{Economic voting} & \textbf{Socionomic voting} \\
\cmidrule[\lightrulewidth](l){2-3}
1. & Rising markets make investors optimistic & 
Optimistic investors make markets rise \\
2. & Recessions result in more cautious business practices & 
More cautious business practices result in recessions\\
3. & Scandals outrage public & 
Outraged public seeks scandals \\
\bottomrule
\end{tabularx}
\caption{Table caption}
\end{table}
\end{frame}
\end{document}

答案2

如果不创建新行,则无法\\在表中使用。解决方案是使用makecell包:它具有\makecell\thead命令,允许定义单元格/列头的通用格式并支持\\。此外,我添加了一个用于项目编号的列并模拟了枚举环境,遵循listliketab包中的想法(我没有使用,因为它似乎与 \makecell 不兼容)。

\documentclass[x11names]{beamer}
\usepackage[utf8]{inputenc}
\usepackage{fourier, heuristica}

\usepackage{booktabs}

\usepackage{makecell}
\renewcommand\theadfont{\bfseries}
\renewcommand\cellalign{lt}

\begin{document}

\begin{frame}
\frametitle{Economic theory vs. Socionomic Theory}
\begin{table}[!h]
\newcounter{tabenum}\setcounter{tabenum}{0}
\newcommand{\tabitem}{\addtocounter{tabenum}{1}\thetabenum.}
\begin{tabular}{@{} >{\color{RoyalBlue3}}r@{\hskip\itemsep}l@{\hskip 4em} l@{}}
\toprule
 & \thead{Economic voting} & \thead{Socionomic voting} \\%
\midrule
\tabitem &\makecell {Rising markets make\\ investors optimistic} & \makecell{Optimistic investors \\ make markets rise} \\
\addlinespace
\tabitem & \makecell{Recessions result in \\ more cautious \\business practices} & \makecell{More cautious\\ business practices \\result in recessions} \\
\addlinespace
\tabitem & \makecell{Scandals outrage \\ public} & \makecell{Outraged public\\ seeks scandals} \\
\bottomrule
\end{tabular}
\caption{Table caption}
\end{table}
\end{frame}

\end{document} 

在此处输入图片描述

相关内容