tabularx を使用するときに、テーブル内のテキストを垂直方向に中央揃えにして Enter キーを追加するにはどうすればよいですか?

tabularx を使用するときに、テーブル内のテキストを垂直方向に中央揃えにして Enter キーを追加するにはどうすればよいですか?

「著者 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}\makecellmakecell

の定義を環境\\内で使用する場合、プリアンブルでは を使用し、テーブルではの代わりにを\centering使用することもできます。>{\centering\let\mynewline\\\arraybackslash}X\mynewline\linebreak

タイプ セルの垂直配置については、垂直方向に中央揃えされたコンテンツに対して、タイプ列の代わりに使用するようXに の定義を変更できます。\tabularxcolumnmp

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

ここに画像の説明を入力してください

関連情報