简体   繁体   English

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

[英]How to split the long headings of a table in multiple lines using latex?

How to create a table using latex exactly as follows.如何使用乳胶创建表格,如下所示。 The table has to fit 1 column in the 2 column page format but the table headings are too long and the content in the first column also too long.表格必须适合 2 列页面格式中的 1 列,但表格标题太长,第一列中的内容也太长。 So, I want to split the column headings and content of the first column in multiple lines with the bold format.所以,我想用粗体格式将第一列的列标题和内容分成多行。

桌子

Not too sure why \\makecell is not co-operating for bold the text and design a solid border all over but here's my latex code:不太清楚为什么 \\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}

The package array provides you a new tabular cell type package array为您提供了一种新的表格单元格类型

p={fixed width}

whit this cell type, you can define two new cell types that meets your alignemt requirements:对于这种单元格类型,您可以定义两种新的单元格类型来满足您的对齐要求:

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

输出

Full code:完整代码:

\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}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM