テーブルの行間に実空間を追加する

Aug 22 2020

特に行列の角かっこが接触しないように、テーブルの行の間にスペースを追加したいと思います。このMWE:

\documentclass{article}

\newcommand*{\mymatrix}[1]{
  \ensuremath{%
    \left[\begin{tabular}{@{}l@{}}#1\end{tabular}\right]%
  }%
}

\begin{document}

\begin{tabular}{*3{l}}
foo & bar & baz\\
foo & \mymatrix{top\\bottom} & baz\\
foo & \mymatrix{top\\bottom} & baz\\
foo & bar & baz\\
\end{tabular}

\end{document}

TeX.SEには、テーブルの行間にスペースを追加する方法を尋ねる質問がたくさんあります。その答えは常に、の値を増やすことを示唆しているようです。\arraystretchたとえば、この質問を参照してください。

しかし、私が知る限り、これは実際には行のにスペース追加するのではなく、単に行を垂直方向に引き伸ばすだけです。私のマトリックスがそうであるように、何かが行の垂直方向のスペースを埋める場合、これらの行の内容はまだ触れています。未満:

\documentclass{article}

\newcommand*{\mymatrix}[1]{
  \ensuremath{%
    \left[\begin{tabular}{@{}l@{}}#1\end{tabular}\right]%
  }%
}

\renewcommand{\arraystretch}{2}

\begin{document}

\begin{tabular}{*3{l}}
foo & bar & baz\\
foo & \mymatrix{top\\bottom} & baz\\
foo & \mymatrix{top\\bottom} & baz\\
foo & bar & baz\\
\end{tabular}

\end{document}

だから私の質問は、テーブルの行のに本当にスペース追加する方法はありますか(スペースを追加しすぎる空の行を挿入する以外に)?

回答

5 Mico Aug 21 2020 at 22:26

これ\addlinespaceがbooktabsパッケージを採用したソリューションです。

\addlinespaceオプションの引数を取ります。これは、挿入する垂直方向の空白の量を示します。引数が指定されていない場合、パッケージによって\defaultaddspace設定されるパラメーターが適用さ0.5emれます。

\documentclass{article}
\newcommand*{\mymatrix}[1]{%
  \ensuremath{\left[\begin{tabular}{@{}l@{}} #1 \end{tabular}\right]}}
\usepackage{booktabs} % for "\addlinespace" macro

\begin{document}

\begin{tabular}{*{3}{l}}
foo & bar & baz\\ 
foo & \mymatrix{top\\bottom} & baz\\ \addlinespace
foo & \mymatrix{top\\bottom} & baz\\ \addlinespace
foo & bar & baz
\end{tabular}
\end{document}
5 F.Pantigny Aug 21 2020 at 23:23

あなたが使用している場合{NiceTabular}nicematrix、2つのオプションがありますcell-space-top-limitし、cell-space-bottom-limit(名前はパラメータに触発されている\cellspacetoplimitcellspacebottomlimitcellspaceあなたはすべてのために一度に設定できること)と、彼らはすべての環境に適用されます{NiceTabular}

\documentclass{article}
\usepackage{nicematrix}
\NiceMatrixOptions{cell-space-top-limit=1pt,cell-space-bottom-limit=1pt}

\newcommand*{\mymatrix}[1]{
  \ensuremath{%
    \left[\begin{tabular}{@{}l@{}}#1\end{tabular}\right]%
  }%
}

\begin{document}

\begin{NiceTabular}{*3{l}}
foo & bar & baz\\
foo & \mymatrix{top\\bottom} & baz\\
foo & \mymatrix{top\\bottom} & baz\\
foo & bar & baz\\
\end{NiceTabular}

\end{document}

4 jsbibra Aug 21 2020 at 22:13

これは問題を解決しますか

追加のパッケージはありません

\documentclass{article}

\newcommand*{\mymatrix}[1]{
  \ensuremath{%
    \left[\begin{tabular}{@{}l@{}}#1\end{tabular}\right]%
  }%
}

\begin{document}

\begin{tabular}{*3{l}}
foo & bar & baz\\
foo & \mymatrix{top\\bottom} & baz\\[8pt]
foo & \mymatrix{top\\bottom} & baz\\[8pt]
foo & bar & baz\\
\end{tabular}

\end{document}

**事前定義されたストラットの追加も機能します**

同じ結果

\def\mystrut{\rule{0pt}{2\normalbaselineskip}}
\begin{tabular}{*3{l}}
    foo & bar & baz\\
    foo & \mymatrix{top\\bottom}\mystrut & baz\\[8pt]
    foo & \mymatrix{top\\bottom}\mystrut & baz\\[8pt]
    foo & bar & baz\\
\end{tabular}
3 Bernard Aug 21 2020 at 22:56

あなたが自動的に欲しいものを得ることは容易であるcellspace文字で始まる指定子列のセルの上部と下部に最小限の垂直方向の間隔を定義する、SまたはCあなたがロードした場合siunitx、またはあなたが通過喜ばでも任意の文字column=読み込み時のオプション:

\documentclass{article}
\usepackage[column=O]{cellspace}
\setlength{\cellspacetoplimit}{3pt}
\setlength{\cellspacebottomlimit}{3pt}

\newcommand*{\mymatrix}[1]{
 \ensuremath{%
    \left[\begin{tabular}{@{}l@{}}#1\end{tabular}\right]%
 }%
}

\begin{document}

\begin{tabular}{*3{Ol}}
foo & bar & baz\\
foo & \mymatrix{top\\bottom} & baz\\
foo & \mymatrix{top\\bottom} & baz\\
foo & bar & baz
\end{tabular}

\end{document}