tabularx 和数组

tabularx 和数组

我的桌子需要两样东西:

  1. 文本必须能够换行。
  2. 第一行必须加粗

对于 1,我需要包tabularx。对于 2,我需要包array和相当多的命令(参见将表格第一行全部设为粗体

但是,如果我将上述命令转置为tabularx(而不是tabular),则显然不起作用。

有任何想法吗?

答案1

从您最初的描述来看,不清楚您是否需要任何包,但我给出了一个使用tabularytabularx的弟弟)的示例,其中列宽是自动选择的。

在此处输入图片描述

\documentclass{article}

\usepackage{tabulary}

\begin{document}

\begin{tabular}{|p{2cm}|p{3cm}|p{2cm}|}
\bfseries\centering some bold words here&
\bfseries\centering and yet more bold&
\bfseries\centering heading for third column\tabularnewline
\hline
normal weight words go here normal weight words go here
normal weight words go here normal weight words go here
&
different words go here different words go here 
different words go here different words go here 
different words go here different words go here 
&
and this is the third column and this is the third column 
and this is the third column and this is the third column 
and this is the third column and this is the third column 
\end{tabular}

\bigskip        

\noindent\begin{tabulary}{\textwidth}{|J|J|J|}
\bfseries\centering some bold words here&
\bfseries\centering and yet more bold&
\bfseries\centering heading for third column\tabularnewline
\hline
normal weight words go here normal weight words go here
normal weight words go here normal weight words go here
&
different words go here different words go here 
different words go here different words go here 
different words go here different words go here 
&
and this is the third column and this is the third column 
and this is the third column and this is the third column 
and this is the third column and this is the third column 
\end{tabulary}

\end{document}

答案2

您还可以使用tabu包及其\rowfont命令可以轻松修改一行中每个单元格的字体和对齐方式:

\documentclass{article}
\usepackage{tabu}
\usepackage{booktabs}

\begin{document}

\noindent\begin{tabu} to \textwidth {@{}XXX<{\strut}@{}}
\toprule
\rowfont[c]{\bfseries} 
some bold words here & and yet more bold & heading for third column \\
\midrule
normal weight words go here normal weight words go here
normal weight words go here normal weight words go here
&
different words go here in the second column
different words go here in the second column
different words go here in the second column
&
and this is the third column and this is the third column 
and this is the third column and this is the third column 
and this is the third column and this is the third column \\ 
\bottomrule
\end{tabu}

\end{document}

在此处输入图片描述

相关内容