我正在嘗試增加表格行之間的空間tabularx
。下面的程式碼工作正常並且完成了我想要的操作:
\begin{tabularx}{5ex}{X}
text \\[2ex]
x
\end{tabularx}
但是,如果文字太長並且無法容納在一行中,則垂直空間不起作用:
\begin{tabularx}{5ex}{X}
text text \\[2ex]
x
\end{tabularx}
請告訴我如何修復程式碼以使其正常工作。要使用的變體(N - 1) * \baselineskip + 2ex
不合適,因為它取決於文字行數N
。
UPD完整範例:
\documentclass{article}
\usepackage{tabularx}
\begin{document}
% code above
\end{document}
答案1
與tabularx
和cellspace
:
\documentclass{article}
\usepackage[column=O]{cellspace}% better, than {} aren't necessary
\setlength\cellspacetoplimit{2ex}
\setlength\cellspacebottomlimit{2ex}
\addparagraphcolumntypes{X}
\usepackage{tabularx} % "tabularx" had to be after "cellspace"
\begin{document}
\begin{tabularx}{5ex}{OX}
\hline
text text \\
\hline
x \\
\hline
\end{tabularx}
\end{document}
hline
添加 s 是為了更好地了解垂直距離)
附tabularray
包裝:
\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{width=5ex,
hlines, % for better visibility of vertical distances
colspec = {X},
rowsep=2ex}
text text \\
x \\
\end{tblr}
\end{document}
結果和以前一樣。
附錄:
顯然問題根本不清楚。從下面的評論來看,只有在某些行之間才需要增加行之間的距離。最簡單的方法是使用\addlinespace[<desired space>]
:
\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\begin{document}
\begin{tabularx}{5ex}{X}
text text \\
text text \\
\addlinespace[2ex] % you can omit this space, if its default value 3pt is ok
x \\
text text \\
\end{tabularx}
\end{document}
答案2
您可以用arraystretch
一個因子來拉伸單元格<F>
:
\renewcommand\arraystretch{<F>}
預設為 1.0。效果是不對稱的,但小因素就可以發揮作用。
除此之外arraystretch
,還可以在單元格內容之前和之後插入和附加不可見元素,例如高度和深度大於單行文字的零長度垂直條。這些條會導致細胞適應此類內容,並且您會獲得增加空間的效果。
這可以在列定義時自動化。如果需要在特定行取消或變更效果,請使用\multicolumn
變更的設定。
\documentclass{article}
\usepackage{tabularx}
\newcommand\upstrut[1][2ex]{\rule[1.5ex]{0pt}{#1}}
\newcommand\lostrut[1][2ex]{\rule[-#1]{0pt}{#1}}
\begin{document}
\begin{tabularx}{9ex}{>{\upstrut}X<{\lostrut}}
\hline
\multicolumn{1}{l}{\textbf{head}} \\
\hline
\multicolumn{1}{l<{\lostrut[4ex]}}{x} \\
text text \\
text text \\
text text \\
\multicolumn{1}{>{\upstrut[4ex]}l}{x} \\
\hline
\end{tabularx}
\end{document}
編輯。然而,如扎爾科的答案,你可以透過使用來簡化事情tabularray
:
\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{
width = 9ex,
colspec = {X},
hline{1-2,Z},
row{3-Y} = {rowsep=2ex},
}
\textbf{head} \\
x \\
text text \\
text text \\
text text \\
x \\
\end{tblr}
\end{document}