5

I'm doing my bachelor thesis, and need to make a table with lots of data. I want to make a macro for that table, since I'm going to use it a few times.

Considering egreg's answer in this question, and the comments to this question. My question is: How can I make this form with a key-value interface, with the use of 19 arguments?

I have used code from Steven's example, and some from the question I mentioned. Below is a complete working example.

\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}

enter image description here

  • 1
    May I suggest to use a key value interface – user31729 Mar 30 '15 at 18:06
  • 2
    expl3 makes key/value interfaces super easy :) – Sean Allred Mar 30 '15 at 18:17
  • Updated my question. I have no idea how to make key-value interface, but it seems like it is the best way to go. – David Kristiansen Mar 31 '15 at 15:01
  • @DavidKristiansen: -1... a complete change from your original question (macro with 19 arguments to a key-value interface, possibly using a single argument) makes the original time invested void. My suggestion would have been to accept that you posted a duplicate question, and then ask another, different question requesting a key-value interface. – Werner Mar 31 '15 at 15:08
  • @Werner: I do accept that, I was simply following a suggestion from a user on another question I made. I have no problem reveting this back to the original, and ask a new one, if that is what I was suppose to do. – David Kristiansen Mar 31 '15 at 15:12
7

Here I use the \getargsC macro of my readarray package to be able to parse a list of space-separated arguments, which are placed in macros named \argi, \argii, etc.. In order to not confuse spaces in the actual argument with the space separators, I enclose each sub-argument in its own brace.

I show, for example, argument 6 with internal spaces.

See below for an ALTERNATE solution using an environment, which alleviates the need to parse 19 arguments.

\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}

enter image description here

ALTERNATIVE environment solution

With this approach, one can use an environment, specifying only those things one needs, such as:

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

While I have simply labeled the inputs as \itemONE, \itemTWO, etc., one could choose more appropriate names to the form.

Here is the full 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}

enter image description here

  • Not that it impacts the answer, but you should use inputenc/fontenc for completion's sake :) – Sean Allred Mar 30 '15 at 18:01
  • 2
    @SeanAllred I will leave that to the reader, as I myself am not sure which encodings are appropriate for which languages. – Steven B. Segletes Mar 30 '15 at 18:16
  • Thanks @StevenB.Segletes. Sean: Actually I'm using XeLaTeX and fontspec package. Didn't see the need for it in the MWE – David Kristiansen Mar 30 '15 at 18:22
8

I show you how to do this form in plain TeX with key-value interface.

\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

The result:

ctr

  • This looks very clean. Can you use this in (Xe)LaTeX someway? I tried to paste it in Overleaf, didn't work of course. – David Kristiansen Mar 31 '15 at 21:04
  • 1
    @DavidKristiansen I don't support LaTeX, i.e. I don't use this in LaTeX. But you can do this. Remove the first five lines (font management and color management using OPmac) and use these by LaTeX packages. Then replace \localcolor\LightGrey by color setting using appropriate LaTeX package and replace \line by \hbox to\hsize in macro code. That is all. The key-value implementation (five lines) can be stay intact. Or you can replace this by LaTeX package but this is more work (and LaTeX package doesn't implement this at five lines). – wipet Apr 1 '15 at 4:18
4

Here's an implementation with a key-value interface:

\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}

enter image description here

With some more work you can also get the colored backgrounds (you need to split the cells, in that case, and color them as you wish.

The \david_cell:nnnnn function is just syntactic sugar for avoiding complicated \multicolumn instructions in the body. The first argument is an optional | for cells at the beginning of the row, the second argument is the number of columns to span (since the least common multiple is 6, it should be easy to spot the pattern), the third argument is the number of intercolumn paddings to subtract (it depends on how many cells are in the row), the fourth is the cell header, the fifth is the contents.

  • I see the pattern, the use of least common multiplier is simple and brilliant, and something I should have thought of initially, insted of making multiple tables. One question: In you example; the spaces are omitted. Is that something that can be fixed with a simple command? – David Kristiansen Mar 31 '15 at 15:29
  • @DavidKristiansen My fault: in the programming environment spaces must be inserted as ~. It should be OK, now. – egreg Mar 31 '15 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.