增加表格行高但不增加与周围文本的间距

增加表格行高但不增加与周围文本的间距

我想构造一个表格环境,它接受一个参数,该参数控制行之间的垂直空间,但不影响表格与周围文本的垂直分离。表格相对于周围文本的一般位置将由封闭列表环境(唯一)控制。以下用于\arraystretch控制行间间距的努力失败,使用替代方法也是如此\extrarowheight。这两个控制序列都会影响表格与周围文本的垂直分离:

\documentclass{article}

\usepackage{lipsum}
\setlength{\parindent}{0pt}

\newenvironment{mytable}[1]{%
    \begin{list}{}{%
        \setlength{\leftmargin}{2em}
        \setlength{\topsep}{5pt}            %desired vertical separation of table from
    }                                       %surrounding text   
        \item
        \renewcommand{\arraystretch}{#1}    %desired vertical space between rows
        \begin{tabular}{ll}
}{%
        \end{tabular}
    \end{list}
}

\begin{document}
\lipsum[1]

\begin{mytable}{3}
    R1C1 & R1C2 \\
    R2C1 & R2C2 \\
    R3C1 & R3C2
\end{mytable}

\lipsum[1] 
\end{document}

有任何想法吗?

答案1

我想你想要类似的东西

在此处输入图片描述

\documentclass{article}

\usepackage{lipsum}
\setlength{\parindent}{0pt}

\newenvironment{mytable}[1]{%
    \begin{list}{}{%
        \setlength{\leftmargin}{2em}
        \setlength{\topsep}{5pt}            %desired vertical separation of table from
    }                                       %surrounding text   
        \item\mbox{}%
        \renewcommand{\arraystretch}{#1}    %desired vertical space between rows
\par
\vspace{\dimexpr\ht\strutbox-\arraystretch\ht\strutbox-\parskip-\baselineskip}%
        \begin{tabular}{ll}
}{%
        \end{tabular}
\par
\vspace{\dimexpr\dp\strutbox-\arraystretch\dp\strutbox}%
    \end{list}
}

\begin{document}
\lipsum[1]

\begin{mytable}{3}
    R1C1 & R1C2 \\
    R2C1 & R2C2 \\
    R3C1 & R3C2
\end{mytable}

\lipsum[1] 
\end{document}

答案2

两个解决方案,使用cellspace包定义最小单元格顶部或底部的垂直间距,或使用makecell,定义垂直间距添加在单元格的顶部或底部:

\documentclass{article}

\usepackage{lipsum}
\setlength{\parindent}{0pt}
\usepackage{cellspace}
\newenvironment{mytable}[1]{%
    \begin{list}{}{%
        \setlength{\leftmargin}{2em}
\setlength\cellspacebottomlimit{1cm}%desired minimal vertical space between rows
        \setlength{\topsep}{5pt} %desired vertical separation of table from
    } %surrounding text
        \item
        \begin{tabular}{SlSl}
}{%
        \end{tabular}
\vspace*{-\cellspacebottomlimit}
    \end{list}
}

\usepackage{makecell}
\newenvironment{myothertable}[1]{%
    \begin{list}{}{%
        \setlength{\leftmargin}{2em}
        \setlength{\topsep}{5pt} %desired vertical separation of table from
\newlength\arrayskip
\setlength\arrayskip{#1}
\setcellgapes[b]{#1}
\makegapedcells
    } %surrounding text
        \item%
        \begin{tabular}{ll}
}{%
        \end{tabular}
\vspace*{-\arrayskip}
    \end{list}
}

\begin{document}
\lipsum[1]

\begin{mytable}{1}
    R1C1 & R1C2 \\
    R2C1 & R2C2 \\
    R3C1 & R3C2
\end{mytable}

\lipsum[2]

\begin{myothertable}{1cm}
    R1C1 & R1C2 \\
    R2C1 & R2C2 \\
    R3C1 & R3C2
\end{myothertable}

\lipsum[3]

\end{document} 

在此处输入图片描述

相关内容