如何在表格中垂直居中文本,例如“作者 1(年份)”,以及如何在表格中的单词之间添加回车符,以使文本相互排列,就像战争、革命和内乱这些词一样?
\begin{table}[H]
\caption{Three levels of political risks}
\label{tab:rcpol}
\footnotesize
\begin{tabularx}{\linewidth}{@{} c *{3}{>{\centering\arraybackslash}X} @{}}
\toprule
\textbf{References} & \textbf{Macro risks} & \textbf{Meso risks} & \textbf{Micro risks} \\
\midrule
Author 1 (Year)
& Corruption
& Government intervention
& Expropriation;
Nationalisation of assets
\\ \midrule
Author 2 (Year)
& War; Revolution; Civil disorders
& \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth
\centering\arraybackslash}X}{%
Inconsistent government policies }
\\
\bottomrule
\end{tabularx}
\end{table}
答案1
在X
类型列中,您可以使用\linebreak
它来插入换行符。在普通单元格中,您可以使用\begin{tabular}{@{} <col> @{}}<content>\end{tabular}
构造来插入换行符(或使用包\makecell
中的构造makecell
,它的作用相同)。
如果您想在环境\\
中使用 的定义\centering
,您也可以>{\centering\let\mynewline\\\arraybackslash}X
在序言和表格中使用\mynewline
而不是\linebreak
。
至于类型单元格的垂直对齐方式:您可以更改为使用类型列而不是垂直居中内容X
的定义。\tabularxcolumn
m
p
\documentclass[]{article}
\usepackage{tabularx}
\usepackage{booktabs}
% change the column type of tabularx to use `m` instead of `p` for the vertical
% centering:
\renewcommand\tabularxcolumn[1]{m{#1}}
\begin{document}
\begin{table}
\caption{Three levels of political risks}
\label{tab:rcpol}
\footnotesize
\begin{tabularx}{\linewidth}{@{} c *{3}{>{\centering\arraybackslash}X} @{}}
\toprule
\textbf{References} & \textbf{Macro risks} & \textbf{Meso risks} & \textbf{Micro risks} \\
\midrule
Author 1 (Year)
& Corruption
& Government intervention
& Expropriation;
Nationalisation of assets
\\ \midrule
Author 2 (Year)
& War; Revolution; Civil disorders
& \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth
\centering\arraybackslash}X}{%
Inconsistent government policies }
\\
author & En-\linebreak forcing\linebreak line\linebreak breaks
\\
\begin{tabular}[]{@{}c@{}}
line\\breaks\\in\\a\\normal\\cell
\end{tabular}
& other cell & other cell
\\
\bottomrule
\end{tabularx}
\end{table}
\end{document}