
\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{Testing 1 testing 2 Testing 3l} &
\seqsplit{Testing 1 testing 2 Testing 3} &
\seqsplit{Testing 1 testing 2 Testing 3} \\
\hline
1 & 2 & 3 & & & \\
1 & 2 & 3 & & & \\
\hline
\end{tabularx}
\caption{tes}
\label{tab:my_label}
\end{table}
\end{document}
這些話應該是
Testing 1 testing 2 Testing 3
但結果卻是
Testing1testing2Testing3
答案1
\hspace{0pt}
您可以先用「隱式空格」取代空格,然後再對應在每個項目後面新增的標記清單。
\documentclass{article}
\usepackage{tabularx}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\spliteverywhere}{m}
{
\tl_set:Nn \l__spliteverywhere_tl { #1 }
\tl_replace_all:Nnn \l__spliteverywhere_tl { ~ } { \c_space_tl }
\tl_map_function:NN \l__spliteverywhere_tl \__spliteverywhere:n
}
\tl_new:N \l__spliteverywhere_tl
\cs_new:Nn \__spliteverywhere:n { #1 \hspace{0pt} }
\ExplSyntaxOff
\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 &
\spliteverywhere{Testing 1 testingtesting 2 Testing 3l} &
\spliteverywhere{Testing 1 testing 2 Testing 3} &
\spliteverywhere{Testing 1 testing 2 Testing 3} \\
\hline
1 & 2 & 3 & & & \\
1 & 2 & 3 & & & \\
\hline
\end{tabularx}
\caption{test}
\label{tab:my_label}
\end{table}
\end{document}
答案2
seqsplit
用於破壞計算機代碼等中的字母序列,對於自然語言文本,最好使用 TeX 的正常換行:
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\begin{table}[htp]
\setlength\extrarowheight{2pt} % for a ever so slightly more open "look"
\begin{tabularx}{\textwidth}{|c |c |c |X |X |X |}
\hline
1 & 2 & 3 &
Testing 1 testing 2 Testing 3l &
Testing 1 testing 2 Testing 3 &
Testing 1 testing 2 Testing 3 \\
\hline
1 & 2 & 3 & & & \\
1 & 2 & 3 & & & \\
\hline
\end{tabularx}
\caption{tes}
\label{tab:my_label}
\end{table}
\end{document}