表格环境中的文本对齐

表格环境中的文本对齐

我想将下表中的文本对齐到顶部和左侧。我对 LaTeX 还很陌生,所以我没有头绪。抱歉,如果这个问题已经有人问过了:

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[german]{babel}
%\usepackage{array}
\usepackage{lscape}
\usepackage{booktabs}
\begin{document}
\newcolumntype{C}[1]{>{\arraybackslash}m{#1}}% I found this somewhere but don't remember where

\begin{landscape}

\begin{tabular}{C{4cm}C{4cm}C{4cm}C{4cm}}     %<--- damit geht es jetzt auch ;)
\toprule
Cluster 1 & Cluster 2 & Cluster 3 & Cluster 4 \\ 
\midrule
\begin{itemize}
 \item Canada, France, Germany
 \item Austria, Belgium, Netherlands, Switzerland
 \item Finland, Iceland, Norway, Sweden
 \item Greece, Portugal, Spain
 \item New Zealand
\end{itemize}
 & 
\begin{itemize}
\item Italy, Japan, United Kingdom, United States
\item Denmark, Ireland
\item Estonia, Hungary
\end{itemize}
 & 
\begin{itemize}
 \item Luxembourg
 \item Czech Republic, Slovenia
 \item Australia, Korea, Turkey
\end{itemize}
 & 
\begin{itemize}
 \item Poland, Slovak Republic
 \item Israel
\end{itemize}
\\
\bottomrule
\end{tabular}

\end{landscape}

\end{document}

答案1

我不确定是否一定要将itemize环境放在表格中,但使用该包,可以轻松控制列表间距。我还创建了一种列类型,可以设置文本不对齐,这对于像您这样的窄列来说更好,并使用将每列的enumitem列标题居中。\multicolumn{1}{c}{...}

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[german]{babel}
\usepackage{array}
\usepackage{lscape}
\usepackage{booktabs}
\usepackage{enumitem} % for control of list spaceing

% This creates a column type with no text justification
\newcolumntype{R}[1]{>{\raggedright\arraybackslash}p{#1}}

\begin{document}
\begin{landscape}

\begin{tabular}{R{4cm}R{4cm}R{4cm}R{4cm}}     %<--- damit geht es jetzt auch ;)
\toprule
% centre headings using \multicolum{1}{c}{...} for each column
\multicolumn{1}{c}{Cluster 1} & \multicolumn{1}{c}{Cluster 2} & \multicolumn{1}{c}
\midrule
\begin{itemize}[nolistsep,leftmargin=*]
 \item Canada, France, Germany
 \item Austria, Belgium, Netherlands, Switzerland
 \item Finland, Iceland, Norway, Sweden
 \item Greece, Portugal, Spain
 \item New Zealand
\end{itemize}
 & 
\begin{itemize}[nolistsep,leftmargin=*]
\item Italy, Japan, United Kingdom, United States
\item Denmark, Ireland
\item Estonia, Hungary
\end{itemize}
 & 
\begin{itemize}[nolistsep,leftmargin=*]
 \item Luxembourg
 \item Czech Republic, Slovenia
 \item Australia, Korea, Turkey
\end{itemize}
 & 
\begin{itemize}[nolistsep,leftmargin=*]
 \item Poland, Slovak Republic
 \item Israel
\end{itemize}
\\
\bottomrule
\end{tabular}

\end{landscape}

\end{document}

代码输出

答案2

我认为,通过对提出的两个解决方案进行一些修改,可以实现以下结果: 在此处输入图片描述

如何?

  1. 评论(如果需要) \begin{landscape}... \end{landscape}
  2. 每列宽度为 3 厘米(而不是 4 厘米)
  3. 在每一列中,你都会得到一条无点线\item[]
  4. 第一行以粗体显示,可以通过以下方式轻松获得

\bf 簇 1 & \bf 簇 2 & \bf 簇 3 & \bf 簇 4 \

相关内容