使用键值接口生成包含 19 个参数的表

使用键值接口生成包含 19 个参数的表

我正在写我的学士论文,需要制作一个包含大量数据的表格。我想为该表格制作一个宏,因为我会用到它几次。

考虑到 egreg 的回答这个问题以及对这个问题的评论。我的问题是:如何使用 19 个参数来制作具有键值接口的表单?

我使用了 Steven 示例中的代码,以及我提到的问题中的一些代码。下面是一个完整的工作示例。

\documentclass[norsk,12pt]{article}
\usepackage{colortbl,tabularx,ifxetex,isodate}

\setlength{\arrayrulewidth}{1pt}
%\setlength{\tabcolsep}{1ex}

\newcolumntype{Y}{|>{\hsize=\dimexpr2\hsize + 2\tabcolsep+\arrayrulewidth\relax}X|}
\newcolumntype{Z}{|>{\hsize=\dimexpr3\hsize+4\tabcolsep+2\arrayrulewidth\relax}X|}

\def\CTRheaderfont{\scriptsize\sffamily}
\def\CTRheaderfontBold{\CTRheaderfont\bfseries}
\def\CTRcoloredrow{\rowcolor[gray]{.9}}

\newcommand\CTRempty[1]{\multicolumn{#1}{X}{}\\}


\newcommand\CTRprosjekt[1]{\def\argi{#1}}
\newcommand\CTRprosjektID[1]{\def\argii{#1}}
\newcommand\CTRoppdragsgiver[1]{\def\argiii{#1}}
\newcommand\CTRstart[1]{\def\argiv{#1}}
\newcommand\CTRferdig[1]{\def\argv{#1}}
\newcommand\CTRvarighet[1]{\def\argvi{#1}}
\newcommand\CTRctr[1]{\def\argvii{#1}}
\newcommand\CTRtittel[1]{\def\argviii{#1}}
\newcommand\CTRdato[1]{\def\argix{#1}}
\newcommand\CTRrev[1]{\def\argx{#1}}
\newcommand\CTRmaal[1]{\def\argxi{#1}}
\newcommand\CTRbeskrivelse[1]{\def\argxii{#1}}
\newcommand\CTRinngangsdata[1]{\def\argxiii{#1}}
\newcommand\CTRleveranser[1]{\def\argxiv{#1}}
\newcommand\CTRkommentar[1]{\def\argxv{#1}}
\newcommand\CTRanskaffelser[1]{\def\argxvi{#1}}
\newcommand\CTRtimer[1]{\def\argxvii{#1}}
\newcommand\CTRutarbeidet[1]{\def\argxviii{#1}}
\newcommand\CTRkontrollert[1]{\def\argxix{#1}}

\newenvironment{CTR}{}{%
%   \cleardoublepage
    \begin{center}
        \begin{tabularx}{\textwidth}{|>{\centering\arraybackslash}X|}
            \hline
            {}\\
            {\bfseries \Large CTR}\\
            {\scshape Cost Time \& Resource}\\
            {}\\\hline
            \CTRempty{1}
        \end{tabularx}
        \begin{tabularx}{\textwidth}{|X|X|X|}
            \hline

            \CTRcoloredrow
            \multicolumn{2}{Y}{\CTRheaderfontBold Prosjekt:}&\CTRheaderfontBold Prosjekt ID: \\
            \CTRcoloredrow
            \multicolumn{2}{Y}{\argi}&\argii \\\hline

            \CTRcoloredrow
            \multicolumn{3}{Z}{\CTRheaderfontBold Oppdragsgiver:}\\
            \CTRcoloredrow
            \multicolumn{3}{Z}{\argiii}\\\hline

            \CTRheaderfont Planlagt start:&\CTRheaderfont Planlagt Ferdig:&\CTRheaderfont Varighet:\\
            \argiv&\argv&\argvi\\\hline

            \CTRheaderfont CTR: (Aktivitetsnummer)&\CTRheaderfont Tittel:&\CTRheaderfont Dato:\\
            \argvii&\argviii&\argix\\
                &&\CTRheaderfont Rev:\\&&\argx \\\hline

            \CTRempty{2}

        \end{tabularx}
        \begin{tabularx}{\textwidth}{|X|X|}
            \hline
            \CTRcoloredrow
            \multicolumn{2}{Y}{\CTRheaderfont M\r{a}l:  (Hva skal oppn\r{a}s med aktiviteten)}\\\hline
            \multicolumn{2}{Y}{\argxi}\\\hline

            \CTRcoloredrow
            \multicolumn{2}{Y}{\CTRheaderfont Arbeidsbeskrivelse: (Hva skal gj{\o}res)}\\\hline 
            \multicolumn{2}{Y}{\argxii}\\\hline

            \CTRcoloredrow
            \multicolumn{2}{Y}{\CTRheaderfont Inngangsdata: (Hva m\r{a} v{\ae}re p\r{a} plass for \r{a} starte aktiviteten (avhengighet))}\\\hline
            \multicolumn{2}{Y}{\argxiii}\\\hline

            \CTRcoloredrow
            \multicolumn{2}{Y}{\CTRheaderfont Leveranser:}\\\hline
            \multicolumn{2}{Y}{\argxiv}\\\hline

            \CTRcoloredrow
            \multicolumn{2}{Y}{\CTRheaderfontBold Kommentarer, antagelser}\\\hline
            \multicolumn{2}{Y}{\argxv}\\\hline

            \CTRcoloredrow
            \multicolumn{2}{|c|}{\CTRheaderfont Ressursbehov}\\\hline

            \CTRheaderfont Anskaffelser:&\CTRheaderfont Timer:\\
            \argxvi&\argxvii\\\hline

            \CTRheaderfont Utarbeidet av:&\CTRheaderfont Kontrollert av:\\
            \argxviii&\argxix\\\hline

        \end{tabularx}
    \end{center}
}
% INITIALIZATIONS
\CTRprosjekt{\sffamily{\textbackslash}CTRprosjekt}
\CTRprosjektID{\sffamily{\textbackslash}CTRprosjektID}
\CTRoppdragsgiver{\sffamily{\textbackslash}CTRoppdragsgiver}
\CTRstart{\sffamily{\textbackslash}CTRstart}
\CTRferdig{\sffamily{\textbackslash}CTRferdig}
\CTRvarighet{\sffamily{\textbackslash}CTRvarighet}
\CTRctr{\sffamily{\textbackslash}CTRctr}
\CTRtittel{\sffamily{\textbackslash}CTRtittel}
\CTRdato{\sffamily{\textbackslash}CTRdato}
\CTRrev{\sffamily{\textbackslash}CTRrev}
\CTRmaal{\sffamily{\textbackslash}CTRmaal}
\CTRbeskrivelse{\sffamily{\textbackslash}CTRbeskrivelse}
\CTRinngangsdata{\sffamily{\textbackslash}CTRinngangsdata}
\CTRleveranser{\sffamily{\textbackslash}CTRleveranser}
\CTRkommentar{\sffamily{\textbackslash}CTRkommentar}
\CTRanskaffelser{\sffamily{\textbackslash}CTRanskaffelser}
\CTRtimer{\sffamily{\textbackslash}CTRtimer}
\CTRutarbeidet{\sffamily{\textbackslash}CTRutarbeidet}
\CTRkontrollert{\sffamily{\textbackslash}CTRkontrollert}

\begin{document}

\CTRprosjekt{1}
\CTRprosjektID{2}
\CTRoppdragsgiver{3}

\begin{CTR}
    \CTRstart{\printdate{01.04.2015}}
    \CTRferdig{\printdate{14.04.2015}}
    \CTRvarighet{14 dager}
    \CTRctr{7}
    \CTRtittel{8}
    \CTRdato{\printdate{31.03.2015}}
    \CTRrev{0.1}
    \CTRmaal{11}
    \CTRbeskrivelse{12}
    \CTRinngangsdata{13}
    \CTRleveranser{14}
    \CTRkommentar{15}
    \CTRanskaffelser{16}
    \CTRtimer{17}
    \CTRutarbeidet{18}
    \CTRkontrollert{19}
\end{CTR}
\end{document}

在此处输入图片描述

答案1

在这里,我使用\getargsC我的readarray包的宏来解析以空格分隔的参数列表,这些参数放在名为\argi\argii等的宏中。为了不将实际参数中的空格与空格分隔符混淆,我将每个子参数括在自己的括号中。

例如,我展示了带有内部空格的参数 6。

请参阅下文备用使用环境的解决方案,从而减轻了解析 19 个参数的需要。

\documentclass[12pt]{article}
\usepackage{readarray}
\def\CTRheaderfont{\scriptsize}
\def\CTRheaderfontBold{\CTRheaderfont\bfseries}

\newcommand{\CTR}[1]{%
\getargsC{#1}
\begin{tabular}{|p{.33\textwidth}|p{.165\textwidth}|p{.165\textwidth}|p{.33\textwidth}|}
    \hline

        \multicolumn{3}{|p{.66\textwidth}|}{{\CTRheaderfontBold Prosjekt:}\newline \argi} 
            & 
        {\CTRheaderfontBold Prosjekt ID:} \newline \argii \\\hline

        \multicolumn{4}{|p{.99\textwidth}|}{{\CTRheaderfontBold Oppdragsgiver:}\newline \argiii}\\\hline

        {\CTRheaderfont Planlagt start:}\newline \argiv
            &
        \multicolumn{2}{|p{.33\textwidth}|}{{\CTRheaderfont Planlagt Ferdig}\newline \argv}
            &
        {\CTRheaderfont Varighet:}\newline \argvi \\\hline

        {\CTRheaderfont CTR ( Aktivitetsnummer:)}\newline \argvii
            &
        \multicolumn{2}{|p{.33\textwidth}|}{{\CTRheaderfont Tittel:}\newline \argviii}
            &
        {\CTRheaderfont Dato:}\newline \argix \newline {\CTRheaderfont Rev:}\newline \argx \\\hline

        \multicolumn{4}{l}{}\\\hline

        \multicolumn{4}{|p{.99\textwidth}|}{{\CTRheaderfont M\r{a}l:  (Hva skal oppnås med aktiviteten)}\newline \argxi}\\\hline

        \multicolumn{4}{|p{.99\textwidth}|}{{\CTRheaderfont Arbeidsbeskrivelse: (Hva skal gjøres)}\newline \argxii}\\\hline

        \multicolumn{4}{|p{.99\textwidth}|}{{\CTRheaderfont Inngangsdata: (Hva må være på plass for å starte aktiviteten (avhengighet))}\newline \argxiii}\\\hline

        \multicolumn{4}{|p{.99\textwidth}|}{{\CTRheaderfont Leveranser}\newline \argxiv}\\\hline

        \multicolumn{4}{|p{.99\textwidth}|}{{\CTRheaderfontBold Kommentarer, antagelser}\newline \argxv}\\\hline

        \multicolumn{4}{|p{.99\textwidth}|}{\CTRheaderfont\centering Ressursbehov}\\\hline

        \multicolumn{2}{|p{.495\textwidth}|}{{\CTRheaderfont Anskaffelser:}\newline \argxvi}
            &
        \multicolumn{2}{|p{.495\textwidth}|}{{\CTRheaderfont Timer:}\newline \argxvii}\\\hline

        \multicolumn{2}{|p{.495\textwidth}|}{{\CTRheaderfont Utarbeidet av:}\newline \argxviii}
            &
        \multicolumn{2}{|p{.495\textwidth}|}{{\CTRheaderfont Kontrollert av:}\newline \argxix}\\\hline

\end{tabular}
}

\begin{document}

\CTR{{1} {2} {3} {4} {5} {6 with spaces} {7} {8} {9} {10} {11} {12} %
  {13} {14} {15} {16} {17} {18} {19}}

\end{document}

在此处输入图片描述

选择环境解决方案

通过这种方法,人们可以使用一个环境,只指定人们需要的东西,比如:

\begin{CTR}
\itemONE{My project title}
\itemNINE{\today}
\end{CTR}

虽然我只是将输入标记为\itemONE\itemTWO等,但人们可以为表单选择更合适的名称。

以下是完整的 MWE:

\documentclass[12pt]{article}

\def\CTRheaderfont{\scriptsize}
\def\CTRheaderfontBold{\CTRheaderfont\bfseries}

\newcommand\itemONE[1]{\def\argi{#1}}
\newcommand\itemTWO[1]{\def\argii{#1}}
\newcommand\itemTHREE[1]{\def\argiii{#1}}
\newcommand\itemFOUR[1]{\def\argiv{#1}}
\newcommand\itemFIVE[1]{\def\argv{#1}}
\newcommand\itemSIX[1]{\def\argvi{#1}}
\newcommand\itemSEVEN[1]{\def\argvii{#1}}
\newcommand\itemEIGHT[1]{\def\argviii{#1}}
\newcommand\itemNINE[1]{\def\argix{#1}}
\newcommand\itemTEN[1]{\def\argx{#1}}
\newcommand\itemELEVEN[1]{\def\argxi{#1}}
\newcommand\itemTWELVE[1]{\def\argxii{#1}}
\newcommand\itemTHIRTEEN[1]{\def\argxiii{#1}}
\newcommand\itemFOURTEEN[1]{\def\argxiv{#1}}
\newcommand\itemFIFTEEN[1]{\def\argxv{#1}}
\newcommand\itemSIXTEEN[1]{\def\argxvi{#1}}
\newcommand\itemSEVENTEEN[1]{\def\argxvii{#1}}
\newcommand\itemEIGHTEEN[1]{\def\argxviii{#1}}
\newcommand\itemNINETEEN[1]{\def\argxix{#1}}
\newenvironment{CTR}{}{
\begin{tabular}{|p{.33\textwidth}|p{.165\textwidth}|p{.165\textwidth}|p{.33\textwidth}|}
    \hline

        \multicolumn{3}{|p{.66\textwidth}|}{{\CTRheaderfontBold Prosjekt:}\newline \argi} 
            & 
        {\CTRheaderfontBold Prosjekt ID:} \newline \argii \\\hline

        \multicolumn{4}{|p{.99\textwidth}|}{{\CTRheaderfontBold Oppdragsgiver:}\newline \argiii}\\\hline

        {\CTRheaderfont Planlagt start:}\newline \argiv
            &
        \multicolumn{2}{|p{.33\textwidth}|}{{\CTRheaderfont Planlagt Ferdig}\newline \argv}
            &
        {\CTRheaderfont Varighet:}\newline \argvi \\\hline

        {\CTRheaderfont CTR ( Aktivitetsnummer:)}\newline \argvii
            &
        \multicolumn{2}{|p{.33\textwidth}|}{{\CTRheaderfont Tittel:}\newline \argviii}
            &
        {\CTRheaderfont Dato:}\newline \argix \newline {\CTRheaderfont Rev:}\newline \argx \\\hline

        \multicolumn{4}{l}{}\\\hline

        \multicolumn{4}{|p{.99\textwidth}|}{{\CTRheaderfont M\r{a}l:  (Hva skal oppnås med aktiviteten)}\newline \argxi}\\\hline

        \multicolumn{4}{|p{.99\textwidth}|}{{\CTRheaderfont Arbeidsbeskrivelse: (Hva skal gjøres)}\newline \argxii}\\\hline

        \multicolumn{4}{|p{.99\textwidth}|}{{\CTRheaderfont Inngangsdata: (Hva må være på plass for å starte aktiviteten (avhengighet))}\newline \argxiii}\\\hline

        \multicolumn{4}{|p{.99\textwidth}|}{{\CTRheaderfont Leveranser}\newline \argxiv}\\\hline

        \multicolumn{4}{|p{.99\textwidth}|}{{\CTRheaderfontBold Kommentarer, antagelser}\newline \argxv}\\\hline

        \multicolumn{4}{|p{.99\textwidth}|}{\CTRheaderfont\centering Ressursbehov}\\\hline

        \multicolumn{2}{|p{.495\textwidth}|}{{\CTRheaderfont Anskaffelser:}\newline \argxvi}
            &
        \multicolumn{2}{|p{.495\textwidth}|}{{\CTRheaderfont Timer:}\newline \argxvii}\\\hline

        \multicolumn{2}{|p{.495\textwidth}|}{{\CTRheaderfont Utarbeidet av:}\newline \argxviii}
            &
        \multicolumn{2}{|p{.495\textwidth}|}{{\CTRheaderfont Kontrollert av:}\newline \argxix}\\\hline

\end{tabular}
}
% INITIALIZATIONS
\itemONE{}
\itemTWO{}
\itemTHREE{}
\itemFOUR{}
\itemFIVE{}
\itemSIX{}
\itemSEVEN{}
\itemEIGHT{}
\itemNINE{}
\itemTEN{}
\itemELEVEN{}
\itemTWELVE{}
\itemTHIRTEEN{}
\itemFOURTEEN{}
\itemFIFTEEN{}
\itemSIXTEEN{}
\itemSEVENTEEN{}
\itemEIGHTEEN{}
\itemNINETEEN{}
\begin{document}
\begin{CTR}
\itemONE{My project title}
\itemNINE{\today}
\end{CTR}
\end{document}

在此处输入图片描述

答案2

我向您展示如何使用键值接口在纯 TeX 中创建这种形式。

\input opmac     % color and font management is here
\input chelvet   % Helvetica font
\letfont\smallfont=\tenrm at8.5pt  % Helvetica at 8.5pt
\input cncent    % NewCentury font
\rulewidth=.8pt

%% the key-value implementation from http://petr.olsak.net/opmac-tricks-e.html#keyval 

\def\kv#1{\expandafter\ifx\csname kv:#1\endcsname \relax
   \expandafter\kvunknown \else \csname kv:#1\expandafter\endcsname\fi 
}
\def\kvunknown{???}
\def\kvscan #1#2=#3,{\ifx#1,\else \kvdef{kv:#1#2}{#3}\expandafter\kvscan\fi}
\let\kvdef=\sdef

%% the formular:

\def\CTR#1{\def\tmpb{#1}\replacestrings{ =}{=}\replacestrings{= }{=}%
   \expandafter\kvscan\tmpb,,=,\CTRa
}
\def\CTRa{\hrule
   \def\tstrut{\lower17pt\vbox to62pt{}} \def\lkern{\kern7pt }
   \CTRl{\hfil\vbox{\hbox to10cm{\hfil\typosize[20/] CTR\hfil}\kern5pt
                    \hbox to10cm{\hfil Cost Time \& Resource\hfil}}}
   \kern15pt
   \def\tstrut{\lower7pt\vbox to35pt{}} \def\lkern{\kern7pt } 
   \hrule
   \shadow \CTRl{\dbl{projekt}{Projekt}\hfil\hfil\vrule\dbl{projektid}{Projekt ID}}
   \shadow  
   \CTRl{\dbl{oppdragsgiver}{Oppdragsgiver}}
   \CTRl{\dbl{planlagtstart}{Planlagt Start}\hfil\vrule
         \dbl{planlagtferdig}{Planlagt Ferdig}\hfil\vrule\dbl{varighet}{Varighet}} 
   \CTRl{\dbl{ctr}{CTR: (Aktivitetsnummer)}\hfil\vrule\dbl{tittel}{Tittel}\hfil\vrule
         \vtop{\dbl{dato}{Dato}\kern10pt\dbl{rev}{Rev}\kern5pt}}
   \kern15pt
   \def\tstrut{\lower7pt\vbox to23pt{}}
   \hrule
   \shadow \CTRl{\smallfont\lkern M\r{a}l:  (Hva skal oppn\r{a}s med aktiviteten)}
   \CTRl{\lkern\kv{mal}}
   \shadow \CTRl{\smallfont\lkern Arbeidsbeskrivelse: (Hva skal gj{\o}res)}
   \CTRl{\lkern\kv{arbeidsbeskrivelse}}
   \shadow \CTRl{\smallfont\lkern Inngangsdata: (Hva m\r{a} v{\ae}re p\r{a} 
                                  plass for \r{a} starte aktiviteten (avhengighet))}
   \CTRl{\lkern\kv{inngangsdata}}
   \shadow \CTRl{\smallfont\lkern Leveranser:}
   \CTRl{\lkern\kv{leveranser}}
   \shadow \CTRl{\smallfont\lkern Kommentarer, antagelser}
   \CTRl{\lkern\kv{kommentarer}} 
   \shadow \CTRl{\smallfont\hfil Ressursbehov}
   \def\tstrut{\lower7pt\vbox to35pt{}}
   \CTRl{\dbl{anskaffelser}{Anskaffelser}\hfil\vrule\dbl{timer}{Timer}}
   \CTRl{\dbl{utarbeidet}{Utarbeidet av}\hfil\vrule\dbl{kontrollert}{Kontrollert av}}
}
\def\dbl#1#2{\vbox{\rlap{\lkern\smallfont #2:}\kern3pt\rlap{\lkern\kv{#1}}}}
\def\CTRl#1{\line{\tstrut\vrule #1\hfil\vrule}\hrule}
\def\shadow{\vbox to0pt{\hbox{\localcolor\LightGrey\tstrut\vrule width\hsize}\vss}\nointerlineskip}

\typosize[12/]
\CTR{
  projekt = 1,
  projektid = 2,
  oppdragsgiver = 3,
  planlagtstart = 1. april 2015,
  planlagtferdig = 14. april 2015,
  varighet = 14 dager,
  ctr = 7,
  tittel = 8,
  dato = 31. mars 2015,
  rev = 0.1,
  mal = 11,
  arbeidsbeskrivelse = 12,
  inngangsdata = 13,   
  leveranser = 14,
  kommentarer = 15,
  anskaffelser = 16,
  timer = 17,
  utarbeidet = 18,
  kontrollert = 19,
}
\bye

结果:

点击率

答案3

以下是具有键值接口的实现:

\documentclass[12pt]{article}

\usepackage{xparse}

\newcommand\CTRheaderfont{\scriptsize}
\newcommand\CTRheaderfontBold{\CTRheaderfont\bfseries}

\ExplSyntaxOn

\cs_new:Nn \david_cell:nnnnn
 {
  \multicolumn{#2}{#1p{\dim_eval:n { #2\textwidth/6-#3\tabcolsep }}|}
   {
    {#4\par}#5
   }
 }

\NewDocumentCommand{\CTR}{m}
 {
  \group_begin:
  \keys_set:nn { david/form } { #1 }
  \par\noindent
  \begin{tabular}{|cccccc|}
  \hline
  \david_cell:nnnnn {|}{4}{4}{\CTRheaderfontBold~Projekt:}
   { \l_david_form_projekt_tl }
  &
  \david_cell:nnnnn {}{2}{2}{\CTRheaderfontBold~Projekt~ID:}
   { \l_david_form_projektid_tl }
  \\
  \hline
  \david_cell:nnnnn {|}{6}{2}{\CTRheaderfontBold Oppdragsgiver:}
   { \l_david_form_oppdragsgiver_tl }
  \\
  \hline
  \david_cell:nnnnn {|}{2}{2}{\CTRheaderfont~Planlagt start:}
   { \l_david_form_planlagtstart_tl }
  &
  \david_cell:nnnnn {}{2}{2}{\CTRheaderfont Planlagt~Ferdig}
   { \l_david_form_planlagtferdig_tl }
  &
  \david_cell:nnnnn {}{2}{2}{\CTRheaderfont Varighet:}
   { \l_david_form_varighet_tl }
  \\
  \hline
  \david_cell:nnnnn {|}{2}{2}{\CTRheaderfont CTR~(Aktivitetsnummer):}
   { \l_david_form_ctr_tl }
  &
  \david_cell:nnnnn {}{2}{2}{\CTRheaderfont Tittel:}
   { \l_david_form_tittel_tl }
  &
  \david_cell:nnnnn {}{2}{2}{\CTRheaderfont Dato:}
   {
    \l_david_form_dato_tl \par\medskip
    {\CTRheaderfont Rev:\par}
    \l_david_form_rev_tl
   }
  \\
  \hline
  \noalign{\medskip}
  \hline
  \david_cell:nnnnn {|}{6}{2}{\CTRheaderfont M\r{a}l:~(Hva~skal~oppn\r{a}s~med~aktiviteten)}
   { \l_david_form_mal_tl }
  \\
  \hline
  \david_cell:nnnnn {|}{6}{2}{\CTRheaderfont Arbeidsbeskrivelse:~(Hva~skal~gj\o~res)}
   { \l_david_form_arbeidsbeskrivelse_tl }
  \\
  \hline
  \david_cell:nnnnn {|}{6}{2}
   {\CTRheaderfont Inngangsdata:~(Hva m\r{a}~v\ae re~p\r{a}~plass~ 
    for~\r{a}~starte~aktiviteten~(avhengighet))}
   { \l_david_form_inngangsdata_tl }
  \\
  \hline
  \david_cell:nnnnn {|}{6}{2}{\CTRheaderfont Leveranser}
   { \l_david_form_leveranser_tl }
  \\
  \hline
  \david_cell:nnnnn {|}{6}{2}{\CTRheaderfontBold Kommentarer,~antagelser}
   { \l_david_form_kommentarer_tl }
  \\
  \hline
  \noalign
   {
    \hbox_to_wd:nn { \textwidth }
     {
      \kern-.5\arrayrulewidth
      \vrule
      \hfil\CTRheaderfont\strut Ressursbehov\hfil
      \vrule
      \kern-.5\arrayrulewidth
     }
   }
  \hline
  \david_cell:nnnnn {|}{3}{2}{\CTRheaderfont Anskaffelser:}
   { \l_david_form_anskaffelser_tl }
  &
  \david_cell:nnnnn {}{3}{2}{\CTRheaderfont Timer:}
   { \l_david_form_timer_tl }
  \\
  \hline
  \david_cell:nnnnn {|}{3}{2}{\CTRheaderfont Utarbeidet~av:}
   { \l_david_form_utarbeidet_tl }
  &
  \david_cell:nnnnn {}{3}{2}{\CTRheaderfont Kontrollert~av:}
   { \l_david_form_kontrollert_tl }
  \\
  \hline
  \end{tabular}
  \par
  \group_end:
 }

\keys_define:nn { david/form }
 {
  projekt .tl_set:N = \l_david_form_projekt_tl,
  projektid .tl_set:N = \l_david_form_projektid_tl,
  oppdragsgiver .tl_set:N = \l_david_form_oppdragsgiver_tl,
  planlagtstart .tl_set:N = \l_david_form_planlagtstart_tl,
  planlagtferdig .tl_set:N = \l_david_form_planlagtferdig_tl,
  varighet .tl_set:N = \l_david_form_varighet_tl,
  ctr .tl_set:N = \l_david_form_ctr_tl,
  tittel .tl_set:N = \l_david_form_tittel_tl,
  dato .tl_set:N = \l_david_form_dato_tl,
  rev .tl_set:N = \l_david_form_rev_tl,
  mal .tl_set:N = \l_david_form_mal_tl,
  arbeidsbeskrivelse .tl_set:N = \l_david_form_arbeidsbeskrivelse_tl,
  inngangsdata .tl_set:N = \l_david_form_inngangsdata_tl,
  leveranser .tl_set:N = \l_david_form_leveranser_tl,
  kommentarer .tl_set:N = \l_david_form_kommentarer_tl,
  anskaffelser .tl_set:N = \l_david_form_anskaffelser_tl,
  timer .tl_set:N = \l_david_form_timer_tl,
  utarbeidet .tl_set:N = \l_david_form_utarbeidet_tl,
  kontrollert .tl_set:N = \l_david_form_kontrollert_tl,
 }
\ExplSyntaxOff

\begin{document}

\CTR{
  projekt = 1,
  projektid = 2,
  oppdragsgiver = 3,
  planlagtstart = 4,
  planlagtferdig = 5,
  varighet = 6,
  ctr = 7,
  tittel = 8,
  dato = 9,
  rev = 10,
  mal = 11,
  arbeidsbeskrivelse = 12,
  inngangsdata = 13,
  leveranser = 14,
  kommentarer = 15,
  anskaffelser = 16,
  timer = 17,
  utarbeidet = 18,
  kontrollert = 19,
}

\end{document}

在此处输入图片描述

通过更多的工作,您还可以获得彩色背景(在这种情况下,您需要拆分单元格,然后根据需要为其着色。

\david_cell:nnnnn函数只是语法糖,用于避免\multicolumn主体中的复杂指令。第一个参数是|行开头单元格的可选项,第二个参数是要跨越的列数(由于最小公倍数是 6,因此应该很容易发现模式),第三个参数是要减去的列间填充数(这取决于行中有多少个单元格),第四个是单元格标题,第五个是内容。

相关内容