如何使用乳胶将表格的长标题分成多行?

问题描述

如何完全按照以下步骤使用乳胶创建表。该表必须适合2列页面格式的1列,但是表标题太长,第一列的内容也太长。因此,我想用粗体格式将第一列的列标题内容分成多行。

table

不太清楚\ makecell为什么不配合使用粗体显示文本并设计出整个边框,但这是我的乳胶代码


\begin{table}[h]    
\begin{center}
\begin{tabularx}{\linewidth}{|L|L|L|L|L|}
\toprule

\makecell[lt]{Type} 
&\makecell[lt]{Financial \\ benefit \\ of the \\users}
& \makecell[lt]{Financial\\ loss of the \\ users} 
&\makecell[lt]{Interruption \\ of user’ \\ daily activity}
&\makecell[lt]{Monetary \\ reward \\ for works}\\

\midrule
\makecell[lt]{Category 1: \\ Work in \\ the retail \\ sector}
 & \ding{51}
 & \ding{51}
 & 
 & \ding{51}\\
 
\midrule
\makecell[lt]{Category 2: \\ Work in \\ the industry \\ sector}
 & \ding{51}
 & \ding{51}
 & \ding{51}
 & \ding{51}\\
 
\midrule
\makecell[lt]{Category 3: \\ Work in \\ the corporate \\ sector}
 & \ding{51}
 & \ding{51}
 & \ding{51}
 & \ding{51}\\
\bottomrule
\end{tabularx}
\end{center}
\end{table}

解决方法

package array为您提供了一种新的表格单元格类型

p={fixed width}

如果是这种单元格类型,则可以定义两种可以满足您的alignemt要求的新单元格类型:

\newcolumntype{F}[1]{%
    >{\raggedright\arraybackslash\hspace{0pt}}p{#1}}%
\newcolumntype{T}[1]{%
    >{\centering\arraybackslash\hspace{0pt}}p{#1}}%

output

完整代码:

\documentclass{article}

\usepackage{array}

\newcolumntype{F}[1]{%
    >{\raggedright\arraybackslash\hspace{0pt}}p{#1}}%
\newcolumntype{T}[1]{%
    >{\centering\arraybackslash\hspace{0pt}}p{#1}}%

\begin{document}

\begin{table}
\begin{tabular}{|F{0.2\textwidth}|T{0.2\textwidth}|T{0.2\textwidth}|T{0.2\textwidth}|T{0.2\textwidth}|}
\hline
\textbf{\hfil Type}&
\textbf{Financial benefit of the users}&
\textbf{Financial loss of the users }&
\textbf{Interruption of user daily activity}&
\textbf{Monetary reward for works}\\ 
\hline
\textbf{Category 1: Work in  the retail  sector } &\textbf{v}&&v&v \\
\hline
\textbf{Category 2: Work in  the industry  sector} &v&v&v&v \\  
\hline
\textbf{Category 3: Work in  the corporate  sector}  &&v&v&v \\
\hline
\end{tabular}
\end{table}

\end{document}