
我有一堆 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 內容會自動轉換為乳膠程式碼,所以我認為我不能使用類似\seqsplit{longword}
.我不太確定是否可能,但我需要一些能夠對整個文件進行斷字或僅針對表格的東西...
答案1
現階段可能還不是最終答案,但評論太長了。我記得並且有一個檔案 allhyph.tex,其中包含當天 TeX 字體中所有 256 個字元之後的連字符連字符模式。我在 CTAN 或網路搜尋上找不到它,所以可能是我寫的。 (相反的 Zerohyph.tex 應作為語言“無連字符”加載。)
但我發現了另一個技巧,它使用普通(預設)英語連字規則。這些模式始終允許在字母l
(ell) 後使用連字符。因此,以永遠無法使用\lowercase
or為代價\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{ }
。對於這個問題來說更重要的是,表格中的大多數列類型都類似於\mbox
並防止所有換行符。我建議將表格環境切換到 tabularx 並使用所有 X 列類型,或從中派生的類型(至於居中),例如
\newcolumntype{C}{>{\centering\arraybackslash}X}
要使某些列比其他 X 列按比例更窄或更寬,您可以看到在 tabularx 列中居中