表の行間の垂直スペース

表の行間の垂直スペース

テーブルの行間のスペースを増やそうとしていますtabularx。次のコードは問題なく動作し、必要なことを行います。

\begin{tabularx}{5ex}{X}
    text \\[2ex]
    x
\end{tabularx}

ただし、テキストが長すぎて 1 行に収まらない場合は、垂直スペースは機能しません。

\begin{tabularx}{5ex}{X}
    text text \\[2ex]
    x
\end{tabularx}

コードを修正して動作させる方法を教えてください。使用するバリアントは(N - 1) * \baselineskip + 2exテキストの行数に依存するため、適切ではありませんN

上院完全な例:

\documentclass{article}

\usepackage{tabularx}

\begin{document}
    % code above
\end{document}

答え1

およびtabularxcellspace:

\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垂直距離の視認性を高めるために が追加されています)

ここに画像の説明を入力してください

パッケージ付き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、セルの内容の前後に、テキストの 1 行分よりも高さと深さが大きい長さゼロの垂直バーなどの目に見えない要素を挿入したり追加したりすることもできます。バーにより、セルがそのような内容に適応し、スペースが広くなったような効果が得られます。

これは列定義時に自動化できます。特定の行で効果をキャンセルまたは変更する必要がある場合は、\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}

ここに画像の説明を入力してください

関連情報