我的桌子需要两样东西:
- 文本必须能够换行。
- 第一行必须加粗
对于 1,我需要包tabularx
。对于 2,我需要包array
和相当多的命令(参见将表格第一行全部设为粗体)
但是,如果我将上述命令转置为tabularx
(而不是tabular
),则显然不起作用。
有任何想法吗?
答案1
从您最初的描述来看,不清楚您是否需要任何包,但我给出了一个使用tabulary
(tabularx
的弟弟)的示例,其中列宽是自动选择的。
\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}