我有一堆类似下面这样的 markdown 表,它们正在使用pandoc
LaTeX PDF 模板转换为 PDF。
| Column1 | Column2 | Column3 | Column4 | Column5 | Column6 | Column7 | Column8 | Column9 | Column10 |
|-----------------------------------------------------------------------------------------------------------------------------------|----------------|---------|---------|---------------------|-------------------------------------------------------------------------------------------------------------|------------------|----------------------------------------------------------------------------------------|-------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|
| Lorem Ipsum verylongwordwithnospacehere simply dummy text of the printing and typesetting indust | Lor | Lor | L | Lor | Lorem Ipsum is simply dumm | Lorem Ipsum i | Lorem Ipsum is simply 9834JKEMKWJ4334DWEE44 the printing and typesetting industry. Lo | Lorem Ipsum is simply dummy text of the printin | Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard |
| Lorem Ipsum is simply dummy text of the printing anotherverylongwordwithoutspace | Lor | Lor | L | Lor | Lorem Ipsum is simply dummy | Lorem Ipsum i | Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsu | Lorem Ipsum is simply dummy text of the printin | Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard |
| Lorem Ipsum is simply dummy Q034DJSKJ32492139DK | Lor | Lor | L | Lor | Lorem Ipsum is simply dummy t | Lorem Ipsum i | Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsu | Lorem Ipsum is simply dummy text of the printin | Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard |
因此,当表格单元格中有长单词或某种长代码时,我得到的输出类似于下面的图片。它们要么被剪切掉,要么溢出到下一列。
我需要的是一种允许单词从任意字母开始换行的方法。也不应该有连字符,所以我用了连\usepackage[none]{hyphenat}
字符。
所以最后,我想要的是这样的:
正如我所说,markdown 内容正在自动转换为 latex 代码,所以我认为我不能使用类似的东西\seqsplit{longword}
。我不太确定是否可行,但我需要一些可以为整个文档启用断字功能或仅针对表格的东西……
答案1
在这个阶段,可能还不是最终答案,但评论太长了。我记得,并且有一个文件 allhyph.tex,其中包含当时 TeX 字体中所有 256 个字符后的连字点的连字模式。我在 CTAN 或网络搜索中找不到它,所以我甚至可能写过它。(相反的 zerohyph.tex 应该作为语言“nohyphenation”加载。)
但是我发现了另一个使用普通(默认)英语连字规则的技巧。模式始终允许在字母l
(ell)后使用连字。因此,以永远无法使用\lowercase
或为代价\MakeLowercase
,将每个字符的小写代码设置为 l 的代码(108)。以下是针对 T1 字体编码的示例。处理大字体编码需要更长的字符代码点列表。
您需要的下一个要素是将字体(适用于所有字体)的连字符设置为小或零宽度空白字符。这就是 \textcompoundwordmark。
另外两件事是你必须告诉 LaTeX 即使在末尾也要使用连字符;并且你需要允许在段落的第一个单词中使用连字符(通常是被阻止的)。
\documentclass{article}
\usepackage[T1]{fontenc} % require \textcompwordmark
\usepackage[english]{babel}
\makeatletter
\newcount\lccodepoint
\def\setAllBreak{\lccodepoint=33 \@whilenum{\lccodepoint<256}\do
{\lccode\lccodepoint=`\l\advance\lccodepoint\@ne}%
\lefthyphenmin\@ne \righthyphenmin\@ne
\hyphenchar\font=\csname\f@encoding\string\textcompwordmark\endcsname
}
\g@addto@macro\selectfont{\setAllBreak}
\AtBeginDocument{\setAllBreak}
% That finishes the setup, except for \everypar below.
\setlength\textwidth{2pt}% ultra-narrow for testing
\setlength\parskip{8pt}
\begin{document}
% This allows hyphenation of the first word in the paragraph
% but can't be in preamble
\everypar{\nolinebreak\hspace{0pt}}
abracadabra
\noindent abracadabra \emph{wowzers}
\end{document}
当然,这不会在不允许换行的地方引入换行符!想想\mbox{ }
。对于这个问题更重要的是,tabular 中的大多数列类型都类似\mbox
,可以防止所有换行符。我建议将 tabular 环境切换到 tabularx 并使用所有 X 列类型,或从中派生的类型(至于居中),例如
\newcolumntype{C}{>{\centering\arraybackslash}X}
要使某些列比其他 X 列按比例变窄或变宽,您可以看到在 tabularx 列中居中