我已经创建了一个表格,并固定了它的宽度,但问题是,当我写一段长文本时,文本会换行,我想在文本应该遵守行宽的情况下添加自动换行符。我该怎么做?我使用了 springer 模板。这是我的表格:
\documentclass{article}
\usepackage{array}
\usepackage{multirow}
\usepackage{graphicx}
\newcommand{\tabitem}{~~\llap{\textbullet}~~}
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%% Table %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{table*}[htp]
\centering
\begin{tabularx}{\textwidth}{|
m{0.2\textwidth}|
p{0.2\textwidth}|
p{0.2\textwidth}|
p{0.1\textwidth}|
p{0.1\textwidth}|
p{0.1\textwidth}|}
\hline
\makecell{Players Interaction}
& \makecell[Xt]{Text Text Text Text Text Texts}
& \makecell[Xt]{Text Text Text Text Text Texts}
& \makecell[Xt]{Text Text Text Text Text Texts}
& Payoff
& Ref \\ \hline
\multirow{4}{=}{Text Text Text Text Text Texts}
& \multirow{2}{=}{Text Text Text Text Text Texts}
& m1 & s1 & p1 & r1 \\ \cline{3-6}
& & m2 & s2 & p2 & r2 \\ \cline{2-6}
& \multirow{2}{=}{Text Text Text Text Text Texts}
& m3 & s3 & p3 & r3 \\ \cline{3-6}
& & Evolutionary game. & \multirow{2}{*}{Text Text Text Text Text Texts.}
& Utility function. & \multirow{2}{*}{Text Text Text Text Text Texts } \\ \cline{1-3} \cline{5-5}
\multirow{4}{=}{Text Text Text Text Text Texts}
& \multirow{3}{=}{Text Text Text Text Text Texts}
& Bankruptcy game. & & Text Text Text Text Text Texts. & \\ \cline{3-6}
& & m6 & s6 & p6 & r6 \\ \cline{3-6}
& & m7 & s7 & p7 & r7 \\ \cline{2-6}
& User vs Net
& m8 & s8 & p8 & r8 \\ \hline
\end{tabularx}
\end{table*}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
答案1
请尝试以下操作:
\documentclass{article}
\usepackage{geometry}
\usepackage{makecell, multirow, tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\begin{table}[htp]
\setcellgapes{2pt}
\makegapedcells
\centering
\begin{tabularx}{\textwidth}{|L|L|L|
p{0.1\textwidth}|
p{0.1\textwidth}|
p{0.1\textwidth}|}
\hline
{Players Interaction}
& {Text Text Text Text Text Texts}
& {Text Text Text Text Text Texts}
& {Text Text Text Text Text Texts}
& Payoff
& Ref \\ \hline
\multirow{5}{=}{Text Text Text Text Text Texts}
& \multirow{2}{=}{Text Text Text Text Text Texts}
& m1 & s1 & p1 & r1 \\ \cline{3-6}
& & m2 & s2 & p2 & r2 \\ \cline{2-6}
& \multirow{3}{=}{Text Text Text Text Text Texts}
& m3 & s3 & p3 & r3 \\ \cline{3-6}
& & Evolutionary game.
& \multirow{6}{=}{Text Text Text Text Text Texts.}
& Utility function.
& \multirow{6}{=}{Text Text Text Text Text Texts} \\ \cline{1-3} \cline{5-5}
\multirow{7}{=}{Text Text Text Text Text Texts}
& \multirow{6}{=}{Text Text Text Text Text Texts}
& \multirow{4}{=}{Bankruptcy game}
& & Text Text Text Text Text Texts.
& \\ \cline{3-6}
& & m6 & s6 & p6 & r6 \\ \cline{3-6}
& & m7 & s7 & p7 & r7 \\ \cline{2-6}
& User vs Net
& m8 & s8 & p8 & r8 \\ \hline
\end{tabularx}
\end{table}
\end{document}
(红线表示页面布局)
与您的 MWE 相比,进行了以下更改:
- 删除了
makcell
列标题中的命令 - 所有
multirow
s 都有=
单元格格式选项 - 跨行文本行数
multirow
采用其实际数量 tabularx
表格必须至少有一X
列,上表中现在使用了三列\textwidth
通过使用包增加geometry
- 添加错过的包裹