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}구문을 사용하여 줄 바꿈을 삽입할 수 있습니다(또는 동일한 작업을 수행하는 패키지 \makecell에서 사용).makecell

\\환경 내부에 있는 것처럼 의 정의를 사용하려면 대신 서문과 테이블에서 을 사용할 \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}

여기에 이미지 설명을 입력하세요

관련 정보