表格中换行的简单方法

表格中换行的简单方法

有没有一种快速且轻松的方法可以在 Latex 中自动断线?

\begin{table}
\centering
\begin{tabular}{rllll}
\multicolumn{1}{l}{id} & nome dashboard & creator~ & tipo & URL                                                                               \\ 
\hline
1                      & user field     & creator  & type & longstringlongstringlongstringlongstringlongstringlongstringlongstringlongstring  \\
2                      & user field     & creator  & type & longstringlongstringlongstringlongstringlongstringlongstringlongstringlongstring  \\
3                      & user field     & creator  & type & longstringlongstringlongstringlongstringlongstringlongstringlongstringlongstring  \\
4                      & user field     & creator  & type & longstringlongstringlongstringlongstringlongstringlongstringlongstringlongstring  \\
5                      & user field     & creator  & type & longstringlongstringlongstringlongstringlongstringlongstringlongstringlongstring  \\
6                      & user field     & creator  & type & longstringlongstringlongstringlongstringlongstringlongstringlongstringlongstring  \\
7                      & user field     & creator  & type & longstringlongstringlongstringlongstringlongstringlongstringlongstringlongstring 
\end{tabular}
\end{table}

我几乎什么都试过了。谢谢。

答案1

这里有一个解决方案,它不会自动换行 URL 字符串,但它仍然快速且轻松:加载包xurl并将 URL 字符串包裹在\url{...}包装器中。

我还想建议加载该tabularx包并tabular用完整的环境替换该环境tabularx

在此处输入图片描述

\documentclass{article}
\usepackage{tabularx,xurl,booktabs}
\begin{document}

\begin{table}
\urlstyle{same} % optional
\begin{tabularx}{\textwidth}{@{} r lll X @{}}
id & nome dashboard & creator & tipo & URL \\ 
\midrule
1 & user field & creator & type & \url{longstringlongstringlongstringlongstringlongstringlongstringlongstringlongstring} \\
2 & user field & creator & type & \url{longstringlongstringlongstringlongstringlongstringlongstringlongstringlongstring}
\end{tabularx}
\end{table}

\end{document}

相关内容