
如何在表格中垂直居中文本,例如“作者 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}