重现 TeXbook 中练习 22.7 的表格

重现 TeXbook 中练习 22.7 的表格

在 TeXbook 的练习 22.7 中,使用模板创建了一个特殊的表\halign

\def\welshverb#1={{\bf#1} = }
\halign{\welshverb#\hfil\tabskip=1em plus 1em&
  \welshverb#\hfil&\welshverb#\hfil\tabskip=0pt\cr
  rydw i=I am& ydw i=am I& roeddwn i=I was\cr
  rwyt ti=thou art& wyt ti=art thou& roeddet ti=thou wast\cr
  mae e=he is& ydy e=is he& roedd e=he was\cr
  mae hi=she is& ydy hi=is she& roedd hi=she was\cr}

在此处输入图片描述 以现代 LaTeX 方式重现该表格的最简单方法是什么?

答案1

你甚至可以做得更好,使用比 Knuth 更简洁的输入语法。

\documentclass{article}
\usepackage{collcell}

\ExplSyntaxOn
\NewDocumentCommand{\welshverb}{m}
 {
  \stephen_welshverb:w #1
 }
\cs_new:Npn \stephen_welshverb:w #1 =
 {
  \textbf{#1}\unskip\ =\ \ignorespaces
 }
\ExplSyntaxOff

\begin{document}

\begin{tabular}{@{} *{3}{>{\collectcell\welshverb}l<{\endcollectcell}} @{}}
  rydw i  = I am     & ydw i  = am I     & roeddwn i  = I was \\
  rwyt ti = thou art & wyt ti = art thou & roeddet ti = thou wast \\
  mae e   = he is    & ydy e  = is he    & roedd e    = he was \\
  mae hi  = she is   & ydy hi = is she   & roedd hi   = she was
\end{tabular}

\end{document}

在此处输入图片描述

答案2

这是一个解决方案,除了从 到的\welshverb微小更改外,它保留了 Knuth 的定义。\bf\bfseries

在此处输入图片描述

\documentclass{article} % or some other suitable document class
\usepackage{array}
\def\welshverb#1={{\bfseries #1} = }

\begin{document}

\begin{tabular}{ *{3}{>{\welshverb}l} }
  rydw i=I am& ydw i=am I& roeddwn i=I was \\
  rwyt ti=thou art& wyt ti=art thou& roeddet ti=thou wast \\
  mae e=he is& ydy e=is he& roedd e=he was \\
  mae hi=she is& ydy hi=is she& roedd hi=she was 
\end{tabular}

\end{document} 

答案3

如果您想使用某种高级语言来完成该任务,您可以使用该collcell包来获取整个单元格内容,并使用 l3 实现按等号进行拆分。

这样可以在输入的等号前后放置可选空格,而不会改变输出(使用 plainTeX 解决方案,您将获得双倍的空格)。

\documentclass{article} % or some other suitable document class
\usepackage{array}

\ExplSyntaxOn
\NewDocumentCommand\welshverbcell{m}
  {
    \tl_if_in:nnTF {#1} { = }
      {
        % implementation here assumes just one = is present at top level (else
        % everything after the second equals sign is lost)
        \seq_set_split:Nnn \l_tmpa_seq { = } {#1}
        \exp_args:Nee \welshverbformat
          { \seq_item:Nn \l_tmpa_seq 1 }
          { \seq_item:Nn \l_tmpa_seq 2 }
      }
      {#1} % ignore cells not containing an equals sign
  }
\ExplSyntaxOff

\NewDocumentCommand\welshverbformat { m m }
  {%
    \textbf{#1} = #2%
  }
\usepackage{collcell}

\begin{document}

\begin{tabular}{ *{3}{>{\collectcell\welshverbcell}l<{\endcollectcell}} }
  rydw i=I am& ydw i=am I& roeddwn i=I was \\
  rwyt ti=thou art& wyt ti=art thou& roeddet ti=thou wast \\
  mae e=he is& ydy e=is he& roedd e=he was \\
  mae hi=she is& ydy hi=is she& roedd hi=she was 
\end{tabular}

\end{document} 

相关内容