\begin{table}[h!]
\centering
\begin{tabular}{l|c |c |c |c |c |c}
1 & 2 & 3 & 4jkjhkjkhjhkjkjkjl & 5fsdsadsadasdsadsadasdsadsa & 6dasdsadasdasdasdasdsadasdsa \\
\hline
1 & 2 & 3 \\
1 & 2 & 3 \\
\end{tabular}
\caption{tes}
\label{tab:my_label}
\end{table}
输出:
如何将“5fsdsadsadasdsadsadasdsadsa”变成两行?例如:
5fsdsadsadasd
sadsadasdsadsa
答案1
你还没有表明有多宽第 4、5 和 6 列应该是。因此,我假设它们应该是同样宽。我进一步假设表格材料的整体宽度应为\textwidth
,即与文本块一样宽。下面的代码采用了tabularx
环境和三列类型X
。
由于没有明显的方法 - 至少对我来说...... - 来决定字符串“5fsdsadsadasdsadsadasdsadsa”和“6dasdsadasdasdasdasdsadasdsa”应该在何处拆分,我将使用宏\seqsplit
来强制在字符串达到相应单元格的宽度时发生换行。
\documentclass{article}
\usepackage{tabularx,seqsplit}
\begin{document}
\begin{table}[h!]
\setlength\extrarowheight{2pt} % for a ever so slightly more open "look"
\begin{tabularx}{\textwidth}{|c |c |c |X |X |X |}
\hline
1 & 2 & 3 &
\seqsplit{4jkjhkjkhjhkjkjkjl} &
\seqsplit{5fsdsadsadasdsadsadasdsadsa} &
\seqsplit{6dasdsadasdasdasdasdsadasdsa} \\
\hline
1 & 2 & 3 & & & \\
1 & 2 & 3 & & & \\
\hline
\end{tabularx}
\caption{tes}
\label{tab:my_label}
\end{table}
\end{document}
答案2
\documentclass{article}
\begin{document}
\begin{table}[htp]% h on its own is asking for trouble
\centering
\begin{tabular}{l|c |c |c |c |c |c}
1 & 2 & 3 & 4jkjhkjkhjhkjkjkjl &
\begin{tabular}{@{}c@{}}5fsdsadsadasd\\sadsadasdsadsa\end{tabular} &
\begin{tabular}{@{}c@{}}6dasdsadasdasd\\asdasdsadasdsa\end{tabular} \\
\hline
1 & 2 & 3 \\
1 & 2 & 3 \\
\end{tabular}
\caption{tes}
\label{tab:my_label}
\end{table}
\end{document}