如何控制表格内公式的间距?

如何控制表格内公式的间距?

我有下表:

\documentclass[12pt, twoside]{report}
\usepackage[a4paper,width=150mm, top=25mm, bottom=25mm, bindingoffset=6mm]{geometry}
\usepackage[backend=biber,style=numeric,hyperref=true]{biblatex}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{makecell}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{amsmath}
\raggedbottom

\begin{document}
\bgroup
\def\arraystretch{1.5}
\begin{table}[!ht]
    \caption{Definition of $mapToReference()$}
    \label{tab:op_map_read_to_reference}
    {\begin{tabular}{l|p{12cm}}
    \toprule
    Inputs & \hangindent=1em$M_{raw} = \{m_i: m_i = (header, payload)\}$ where $m.payload = r = (s\_id, r\_id, b, q, f_p)$ as in. \\
    \cline{2-2}
    Operation & $mapToReference(r, ref\_id)$\\
    \cline{2-2}
    \multirow{2}{*}{Outputs} & \hangindent=1em$M_{aln} = \{m_i: m_i = (header, r)\} \text{ where } r = (s\_id, ref\_id, r\_id, b, q, f_p, rname, pos, mapq, cigar, flags)$\\
    & \hangindent=1em $M_{unaln} = \{m_i: m_i = (header, r)\} \text{  where } r = (s\_id, r\_id, b, q, f_p, unmapped=true)$\\
    \bottomrule
    \end{tabular}}
\end{table}
\egroup
\end{document}

这会产生一个丑陋的表格,其中公式(尤其是输出部分中的公式)被拉长了。我想知道控制这些单元格布局的最佳方法是什么。我不想要任意的水平间距,并且我希望能够在任何我想要的地方引入换行符。

谢谢。

答案1

一些建议:

  • 使用明确的数学斜体,而不是普通的数学模式,来排版变量名;在下面的代码中,这是通过\vn(“变量名”)宏实现的。

  • 使用明确的换行符。

  • 使用更少的花括号:许多花括号除了造成代码混乱外根本没有任何作用。

在此处输入图片描述

\documentclass[12pt, twoside]{report}
\usepackage[a4paper,width=150mm, vmargin=25mm, 
            bindingoffset=6mm]{geometry}
\usepackage{array,booktabs,ragged2e,amsmath}
\raggedbottom
\newcommand\vn[1]{\mathit{#1}}

\begin{document}

\begin{table}[!ht]
\def\arraystretch{1.25}
    \caption{Definition of $\vn{mapToReference}()$}
    \label{tab:op_map_read_to_reference}
    \centering
    \begin{tabular}{@{}l>{\RaggedRight}p{12cm}@{}}
    \toprule
    Inputs & $\vn{M_{raw}} = \{m_i: m_i = (\vn{header}, \vn{payload})\}$ where \\
    & \qquad $\vn{m.payload} = r = (s\_id, r\_id, b, q, f_p)$ as in. \\
    \cmidrule(l){2-2}
    Operation & $\vn{mapToReference}(r, \vn{ref\_id})$\\
    \cmidrule(l){2-2}
    Outputs & $\vn{M_{aln}} = \{m_i: m_i = (\vn{header}, r)\}$, 
    where \\
    & \qquad $r = (s\_id, \vn{ref}\_id, r\_id, b, q, f_p, 
    \vn{rname}, \vn{pos}, \vn{mapq}, \vn{cigar}, \vn{flags})$\\
    & $\vn{M_{unaln}} = \{m_i: m_i = (\vn{header}, r)\}$, where \\
    & \qquad $r = (s\_id, r\_id, b, q, f_p, \vn{unmapped=true})$\\
    \bottomrule
    \end{tabular}
\end{table}

\end{document}

相关内容