我有一个软件程序可以生成表格,这些表格可能很长,可能包含很多字母的单词,所以我使用longtabu
包。有些单词可能看起来像这样:
AAA_BBB_CCCC_DDDDD_CC
抱歉,暂无相关信息
因此我使用\allowbreak\_
和 \allowbreak\::
来拆分某些表格单元格中的长单词。但问题是,如果下划线或冒号后面的单词太长,则无法拆分。Longtabu 可以拆分长单词,但不能拆分下划线或冒号后面的单词……而且这些长单词都是由软件程序生成的,我无法手动添加任何拆分。
那么如何破解它?下面是代码和pdf。
\documentclass[a4paper,leqno,twoside]{article}
\usepackage[utf8]{inputenc}
\title{dd}
\usepackage{tabu}
\usepackage{longtable}
\usepackage{supertabular}
\usepackage{hyperref}
\begin{document}
\maketitle
\section{Introduction}
There is a story \hyperlink{ABCDoABCoABCDoABCDDoABBoE}{alsdfas\_alsdjfa\_lasdkfjal\_alsdkfj}
\subsection{asdf asdfasf asdfasd}
\begin{longtabu} to \textwidth {|>{\footnotesize}X[1 , p ] |>{\footnotesize}X[1 , p ] | >{\scriptsize}X[1 , p ]| >{\footnotesize}X[2 , p ]|>{\footnotesize}X[1 , p ]|>{\footnotesize}X[1 , p ]|}
\caption{asdf asfas}\\
\hline
\textbf{aaaaaa;\newline asdfasd} & \textbf{asdfasdf;\newline asdfasdf;\newline asdfasdf;\newline asdfa;\newline asdfasdfasfasfasdf\newline} & \footnotesize\textbf{asdfasdfas} & \textbf{asdfasdfs} & \textbf{asdfasdf;\newline asdfasdfasdf asdf asdfas} & \textbf{asdfasdfasd} \\
\hline
\hypertarget{ABCDoABCoABCDoABCDDoABBoE}{ABCD\allowbreak\_ABC\allowbreak\_ABBVASDFASDDDD\allowbreak\_ABC\allowbreak\_ABC\allowbreak \_A}&&Caa:: CaaaaaaaBddddd\allowbreak::EabadfkajdlEadlsfjaDalsdfjalsdf
&&&\\\hline
\end{longtabu}
\end{document}
答案1
您需要让 TeX 认为在这些断点之后它正在开始一个新单词,以便允许对以下部分进行连字。 \hspace{0pt}
将完成这样的断点。最好将您的代码收集到自定义命令中,以便在给定的标点符号处允许行为:
\documentclass[a4paper,leqno,twoside]{article}
\usepackage[utf8]{inputenc}
\title{dd}
\usepackage{tabu}
\usepackage{longtable}
\usepackage{supertabular}
\usepackage{hyperref}
\newcommand{\uscbr}{\allowbreak\_\allowbreak\hspace{0pt}}
\newcommand{\ccbr}{\allowbreak::\hspace{0pt}}
\begin{document}
\maketitle
\section{Introduction}
There is a story
\hyperlink{ABCDoABCoABCDoABCDDoABBoE}{alsdfas\_alsdjfa\_lasdkfjal\_alsdkfj}
\subsection{asdf asdfasf asdfasd}
\begin{longtabu} to \textwidth {|>{\footnotesize}X[1 , p ] |>{\footnotesize}X[1 , p ] | >{\scriptsize}X[1 , p ]| >{\footnotesize}X[2 , p ]|>{\footnotesize}X[1 , p ]|>{\footnotesize}X[1 , p ]|}
\caption{asdf asfas}\\
\hline
\textbf{aaaaaa;\newline asdfasd} & \textbf{asdfasdf;\newline asdfasdf;\newline asdfasdf;\newline asdfa;\newline asdfasdfasfasfasdf\newline} & \footnotesize\textbf{asdfasdfas} & \textbf{asdfasdfs} & \textbf{asdfasdf;\newline asdfasdfasdf asdf asdfas} & \textbf{asdfasdfasd} \\
\hline
\hypertarget{ABCDoABCoABCDoABCDDoABBoE}{ABCD\uscbr ABC\uscbr
ABBVASDFASDDDD\uscbr ABC\uscbr ABC\uscbr A}&&Caa:: CaaaaaaaBddddd\ccbr
EabadfkajdlEadlsfjaDalsdfjalsdf
&&&\\\hline
\end{longtabu}
\end{document}