我有这张桌子
\documentclass{article}
\usepackage{tabulary}
\begin{document}
\begin{table}[htbp]
\begin{tabulary}{\textwidth}{lLLLrr}
\hline
\textbf{type} & \textbf{author} & \textbf{title} & \textbf{about} & \textbf{year} & \textbf{ref} \\ \hline
book & David Salomon and Giovanni Motta & Handbook of Data Compression & general & 2010 & [1] \\
article & Senthil Shanmugasundaram and Robert Lourdusamy & A Comparative Study Of Text Compression Algorithms & text compr. & 2011 & [2] \\
article & Kitty Arora and Manshi Shukla & A Comprehensive Review of Image Compression Techniques & image compr. & 2014 & [3] \\ \hline
\end{tabulary}
\end{table}
\end{document}
我不想在列中使用连字符“关于”。但我仍然希望在必要的地方使用换行符。因此,“general”和“image”这两个词不应使用连字符(本列中的任何其他词也不应使用连字符),但“text”和“compr.”之间以及“image”和“compr.”之间应有换行符。
其他列应允许使用连字符。我想要名称“尚穆加桑达拉姆”要用连字符连接,标题中的长单词也需要用连字符连接(我的例子中未显示)。
我尝试使用其他符号来定义列(l、L、r 除外),但表格看起来不好看,而且仍然会出现连字符。我还尝试使用{\raggedright general}
代替general
,但这没有效果。
我该怎么做才能避免列中出现连字符“关于”?
答案1
您可以将连字惩罚设置\hyphenpenalty
为该\exhyphenpenalty
特定列的“无限”值,如TeX 常见问题解答但是,这会导致长字(注意第 4 行)重叠,可以通过设置该列的特定宽度来防止这种情况。
\documentclass{article}
\usepackage{tabulary}
\begin{document}
\begin{table}[htbp]
\begin{tabulary}{\textwidth}{lLL>{\hyphenpenalty=10000\exhyphenpenalty=10000}Lrr}
\hline
\textbf{type} & \textbf{author} & \textbf{title} & \textbf{about} & \textbf{year} & \textbf{ref} \\ \hline
book & David Salomon and Giovanni Motta & Handbook of Data Compression & general & 2010 & [1] \\
article & Senthil Shanmugasundaram and Robert Lourdusamy & A Comparative Study Of Text Compression Algorithms & text compr. & 2011 & [2] \\
article & Kitty Arora and Manshi Shukla & A Comprehensive Review of Image Compression Techniques & image compr. & 2014 & [3] \\
article & Kitty Arora and Manshi Shukla & A Comprehensive Review of Image Compression Techniques & imagefhdfjk compr. & 2014 & [3] \\\hline
\end{tabulary}
\end{table}
\end{document}
附录:
您还可以使用tabularray
允许在单元格中手动换行的包。
\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{table}[htbp]
\begin{tblr}{
width=\textwidth,
colspec = {lX[l]X[l, 1.5]lrr},
row{1} = {font=\bfseries}
}
\hline
type & author & title & about & year & ref \\ \hline
book & David Salomon and Giovanni Motta & Handbook of Data Compression & general & 2010 & [1] \\
article & Senthil Shanmugasundaramasks and Robert Lourdusamy & A Comparative Study Of Text Compression Algorithms & {text\\compr.} & 2011 & [2] \\
article & Kitty Arora and Manshi Shukla & A Comprehensive Review of Image Compression Techniques & {image\\compr.} & 2014 & [3] \\
\hline
\end{tblr}
\end{table}
\end{document}
此包使处理表格变得非常容易和方便。请注意,默认情况下行与行之间的间距更好。
答案2
我会采取不同的方法:您的列太窄,难以阅读。我的建议是将作者和标题设置在同一列中,并使用缩写来表示“关于”列。
\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\begin{document}
\begin{table}[htbp]
\begin{tabularx}{\textwidth}{@{}l>{\raggedright}Xccc@{}}
\toprule
Type & Author and Title & About & Year & Ref \\
\midrule
book &
David Salomon and Giovanni Motta \\
\itshape Handbook of Data Compression &
G & 2010 & [1]
\tabularnewline\addlinespace
article &
Senthil Shanmugasundaram and Robert Lourdusamy \\
\itshape A Comparative Study Of Text Compression Algorithms &
TC & 2011 & [2]
\tabularnewline\addlinespace
article &
Kitty Arora and Manshi Shukla \\
\itshape A Comprehensive Review of Image Compression Techniques &
IC & 2014 & [3]
\tabularnewline
\midrule[\heavyrulewidth]
\multicolumn{5}{@{}l@{}}{G: general; IC: image compression; TC: text compression}
\end{tabularx}
\end{table}
\end{document}