Bigtable 不会自动断开包含点的文本行

Bigtable 不会自动断开包含点的文本行

我正在处理一份 PDF 报告,该报告来自从应用程序接收的数据,并记录到格式化的 .tex LaTeX 文件中。此报告的目的是将数据呈现为一个长表,该表可以跨越多页。到目前为止,一切都运行良好,除了具有自然带点的主机名的单元格,例如 myhost.mydomain.example.com。用户ID如果主机名带有点,列不会自动换行。例如,当我用破折号替换点时,自动换行功能可以正常工作。这是我的代码:

\documentclass[10pt]{report}
\usepackage{longtable}
\usepackage{pdflscape}
\usepackage{array}
\usepackage[left=1.5cm,right=1.5cm,top=1cm,bottom=1cm,includeheadfoot,landscape]{geometry}
\usepackage{microtype}
\begin{document}
\fontfamily{phv}\selectfont
\clearpage
\footnotesize
\begin{longtable}{|p{2cm}|p{2.5cm}|p{2cm}|p{2cm}|p{2cm}|p{1.5cm}|p{2.8cm}|p{2.5cm}|p{2cm}|p{2cm}|}
\hline
\textbf{id} & \textbf{mac} & \textbf{uri} & \textbf{ip} & \textbf{netdevip} & \textbf{netdevport} & \textbf{netdevportid} & \textbf{netdevmac} & \textbf{ssid} & \textbf{uid}\\ \hline
\endhead

000000000002&00:00:00:00:00:02&c181af20-5594-11e8-bb9e-6e6163636f72&200.200.200.201&200.200.200.200&50004&FastEthernet0/4&00:00:00:00:00:01&&\\ \hline                                                                                                                       
000000000003&00:00:00:00:00:03&&0.0.0.0&10.10.10.1&50102&GigabitEthernet1/0/2&00:00:00:00:00:00&&myhostname.mysubdomain.mydomain.example.com\\ \hline                                                                                                                        
000000000004&00:00:00:00:00:04&&0.0.0.0&10.10.10.2&50102&GigabitEthernet1/0/2&00:00:00:00:00:00&&otherhostname.mysubdomain.mydomain.example.com\\ \hline                                                                                                                     
000000000005&00:00:00:00:00:05&&0.0.0.0&10.10.10.3&50102&GigabitEthernet1/0/2&00:00:00:00:00:00&&\\ \hline

\end{longtable}
\clearpage
\end{document}

输出如下所示:

主机名带有点的单元

输出将点替换为破折号:

主机名带有破折号的单元

任何有助于理解此行为并解决问题的帮助都非常受欢迎!

答案1

您可以加载xurl并使用该\url命令。下面是一段代码,我在其中使用了tabularx环境。包将ltablexs的功能带到了。我将列说明符重新定义为或,使用了的值,并使用来自包的为单元格添加了一些垂直填充:longtabletabularxlX\tabcolsep\setcellgapes...\makegapedcellsmakecell

\documentclass[10pt]{report}
\usepackage{ltablex}
\usepackage{pdflscape}
\usepackage{array}
\usepackage[hmargin=1.5cm, vmargin=1cm, includeheadfoot, landscape, showframe]{geometry}
\usepackage{xurl, makecell}
\def\UrlFont{\sffamily}
\usepackage{microtype}

\begin{document}

\fontfamily{phv}\selectfont%
\footnotesize
\setlength{\tabcolsep}{4pt}
\setcellgapes{4pt}\makegapedcells
\begin{tabularx}{\linewidth}{|l|l|X|l|l|l|l|l|p{2cm}|X|}
\hline
\textbf{id} & \textbf{mac} & \textbf{uri} & \textbf{ip} & \textbf{netdevip} & \textbf{netdevport} & \textbf{netdevportid} & \textbf{netdevmac} & \textbf{ssid} & \textbf{uid}\\ \hline
\endhead

000000000002&00:00:00:00:00:02& \url{c181af20559411e8bb9e6e6163636f72} &200.200.200.201 & 200.200.200.200 & 50004 & FastEthernet0/4 & 00:00:00:00:00:01 & & \\
\hline
000000000003&00:00:00:00:00:03&&0.0.0.0&10.10.10.1&50102&GigabitEthernet1/0/2&00:00:00:00:00:00&& \url{myhostname.mysubdomain.mydomain.example.com} \\
\hline
000000000004&00:00:00:00:00:04&&0.0.0.0&10.10.10.2&50102&GigabitEthernet1/0/2&00:00:00:00:00:00&& \url{otherhostname.mysubdomain.mydomain.example.com}\\
\hline
000000000005&00:00:00:00:00:05&&0.0.0.0&10.10.10.3&50102&GigabitEthernet1/0/2&00:00:00:00:00:00&&\\ \hline

\end{tabularx}
\clearpage

\end{document} 

在此处输入图片描述

答案2

我建议您加载url包并将单元格内容放在\url{...}指令的最后一列中。

在此处输入图片描述

\documentclass[10pt]{report}
\usepackage{longtable}
\usepackage{pdflscape}
\usepackage{array}
\usepackage[hyphens,spaces,obeyspaces]{url} % <-- new
\urlstyle{sf}
\usepackage[hmargin=1.5cm,vmargin=1cm,
            includeheadfoot,landscape]{geometry}
\usepackage{microtype}

\begin{document}
\fontfamily{phv}\selectfont
\footnotesize
\setlength\extrarowheight{2pt}  % for a more open "look"
\setlength\tabcolsep{5pt}       % default : 6pt
\begin{longtable}{|p{2cm}  |p{2.5cm}|p{2cm}|  p{2cm}|p{2cm}|
                   p{1.5cm}|p{2.8cm}|p{2.5cm}|p{2cm}|p{2cm}|}
\hline
\textbf{id} & \textbf{mac} & \textbf{uri} & \textbf{ip} &
\textbf{netdevip} & \textbf{netdevport} &
\textbf{netdevportid} & \textbf{netdevmac} & 
\textbf{ssid} & \textbf{uid}\\ 
\hline
\endhead

\hline
\endlastfoot

000000000002&00:00:00:00:00:02&c181af20-5594-11e8-bb9e-6e6163636f72&200.200.200.201&200.200.200.200&50004&FastEthernet0/4&00:00:00:00:00:01&&\\
\hline
000000000003&00:00:00:00:00:03&&0.0.0.0&10.10.10.1&50102&GigabitEthernet1/0/2&00:00:00:00:00:00&&\url{myhostname.mysubdomain.mydomain.example.com}\\
\hline
 000000000004&00:00:00:00:00:04&&0.0.0.0&10.10.10.2&50102&GigabitEthernet1/0/2&00:00:00:00:00:00&&\url{otherhostname.mysubdomain.mydomain.example.com}\\
\hline
000000000005&00:00:00:00:00:05&&0.0.0.0&10.10.10.3&50102&GigabitEthernet1/0/2&00:00:00:00:00:00&&\\

\end{longtable}

\end{document} 

相关内容