表格环境中的文本格式

表格环境中的文本格式

我想让单词“words words words”直接位于 下方n^k。到目前为止,我尝试过的方法都没有奏效。也就是说,\newline\\\underset{}无法实现我的愿望。

示例代码

\begin{center}
  \begin{tabular}{ | l | l | p{5cm} |}
    \hline
     & Order Matters & Order Doesn't Matter  \\ \hline
    Repetition Allowed & $\displaystyle{n^k} $\par{ words words words}& $\displaystyle {n+k-1 \choose k-1}$ \\ \hline
    No Repetition Allowed& $\frac{n!}{(n-k)!}$ & ${n \choose k}$  \\ \hline
  \end{tabular}
\end{center}

答案1

您只能\par在固定宽度的p列内使用。以下是您的简化实现tabular

在此处输入图片描述

\documentclass{article}
\usepackage{amsmath,booktabs}
\begin{document}

\begin{center}
  \begin{tabular}{ l c c }
    \toprule
     & Order Matters & Order Doesn't Matter \\
    \cmidrule{2-3}
    Repetition Allowed & $\underset{\text{words words words}}{n^k}$ & $\binom{n+k-1}{k-1}$ \\[.5\normalbaselineskip]
    No Repetition Allowed & $\frac{n!}{(n-k)!}$ & $\binom{n}{k}$ \\
    \bottomrule
  \end{tabular}
\end{center}

\end{document}

它使用\binom来自amsmath而不是 plain-TeX \choose\displaystyle可用版本为\dbinom


另一个允许根据需要分段的选项(借助varwidth。使用 创建一个固定宽度的列,L{<width>}它将产生一个L不超过 宽度的左对齐列<width>

在此处输入图片描述

\documentclass{article}
\usepackage{amsmath,booktabs,varwidth,collcell}

\newcommand{\fixedwidthcolumn}[1]{%
  \begin{varwidth}[t]{\fcolwidth}%
    \raggedright
    \strut#1\strut
  \end{varwidth}}

\newcolumntype{L}[1]{>{\gdef\fcolwidth{#1}\collectcell\fixedwidthcolumn}l<{\endcollectcell}}
\begin{document}

\begin{center}
  \begin{tabular}{ l c c }
    \toprule
     & Order Matters & Order Doesn't Matter \\
    \cmidrule{2-3}
    Repetition Allowed & $\underset{\text{words words words}}{n^k}$ & $\binom{n+k-1}{k-1}$ \\[.5\normalbaselineskip]
    No Repetition Allowed & $\frac{n!}{(n-k)!}$ & $\binom{n}{k}$ \\
    \bottomrule
  \end{tabular}

  \bigskip

  \begin{tabular}{ L{130pt} c c }
    \toprule
     & Order Matters & Order Doesn't Matter \\
    \cmidrule{2-3}
    Repetition Allowed & $\underset{\text{words words words}}{n^k}$ & $\binom{n+k-1}{k-1}$ \\[.5\normalbaselineskip]
    No Repetition Allowed & $\frac{n!}{(n-k)!}$ & $\binom{n}{k}$ \\
    \bottomrule
  \end{tabular}

  \bigskip

  \begin{tabular}{ L{130pt} c c }
    \toprule
     & Order Matters & Order Doesn't Matter \\
    \cmidrule{2-3}
    Some text that is long and will most like span multiple lines (but be not wider than \texttt{130pt}) & 
      $\underset{\text{words words words}}{n^k}$ & $\binom{n+k-1}{k-1}$ \\
    No Repetition Allowed & $\frac{n!}{(n-k)!}$ & $\binom{n}{k}$ \\
    \bottomrule
  \end{tabular}
\end{center}

\end{document}

答案2

这使用了一个额外的p(arbox)列,但没有将文本居中(因为这不是要求的)

\documentclass{article}

\usepackage{mathtools}

\begin{document}

\begin{center}
  \begin{tabular}{ | l | p{3cm} | p{5cm} |}
    \hline
     & Order Matters & Order Doesn't Matter  \\ \hline
    Repetition Allowed & $\displaystyle{n^k}$ \linebreak words words words & $\displaystyle {n+k-1 \choose k-1}$ \\ \hline
    No Repetition Allowed& $\frac{n!}{(n-k)!}$ & ${n \choose k}$  \\ \hline
  \end{tabular}
\end{center}

\end{document}

在此处输入图片描述

相关内容