1

Background

A generated document contains tables with and without headers. For the tables with headers there is no issue, as exemplified by:

Header row

Problem

The generated document does not include a horizontal line for the table when there is no header:

No header row

The desired output has a border before the table body begins:

Desired header row

Code

The generated table code:

\startplacetable[location=none]
\startxtable
\startxtablebody[body]
\startxrow
\startxcell[align=right,width={0.50\textwidth}] {\bf ID} \stopxcell
\startxcell[align=right,width={0.50\textwidth}] FSA-1 \stopxcell
\stopxrow
\stopxtable
\stopplacetable

The styling code:

\setupxtable[
  frame=off,
  option={stretch,width},
  split=yes,
  header=repeat,
]
\setupxtable[head][topframe=on,bottomframe=on]
\setupxtable[foot][bottomframe=on]

Adding code to style just the body causes all lines to have a border. For example:

\setupxtable[body][topframe=on,bottomframe=off]

Produces:

Table with body style

And the following error message appears:

setup           > error in line 8, namespace 'xtable', key 'body'

Question

How can the first row, and only the first row, of an xtable body be styled to have a border (such that the desired output is produced)?

Note that the bottom border for the header row will have to be disabled to avoid doubling up the line. Also note that since the code is generated, it is not feasible to modify each xtable instance. Ideally, the border can be added using setupxtable. The documentation is lacking in this area.

Environment

  • ConTeXt MKIV 2018.01.04 17:37
3
  • My ConTeXt version does not compile xtable but I would give a try to \startxrow[topframe=on,bottomframe=on]. Sorry I can't check this.
    – sztruks
    Jan 8, 2018 at 19:36
  • Not possible, see this thread: mailman.ntg.nl/pipermail/ntg-context/2018/090527.html Jan 8, 2018 at 20:10
  • 1
    BTW, those “errors” are there because you are not using the pandoc preamble. Simply add \setupxtable[head,body,foot][] to your document to make them disappear. Jan 8, 2018 at 22:31

1 Answer 1

1

There is no automated high-level way to do this, as already discussed on the ConTeXt mailing list (https://mailman.ntg.nl/pipermail/ntg-context/2018/090527.html). You can however, hack your way into the \startxrow macro and branch on the first row (index 0).

The table in your question is incomplete and I doubt that it was generate like this by pandoc. The resulting document does not typeset. I have completed the table with some bogus content.

\unprotect

\unexpanded\def\startxrow
  {\begingroup
   \ifnum\currentxtablerow=0
     \setupcurrentxtable[topframe=on]
   \fi
   \doifelsenextoptionalcs\tabl_x_start_row_yes\tabl_x_start_row_nop}

\protect

\setupxtable[
  frame=off,
  option={stretch,width},
  split=yes,
  header=repeat,
]
\setupxtable[head][topframe=on,bottomframe=on]
\setupxtable[body][]
\setupxtable[foot][bottomframe=on]

\starttext

\startplacetable[location=none]
  \startxtable
    \startxtablebody[body]
      \startxrow
        \startxcell[align=right,width={0.50\textwidth}] {\bf ID} \stopxcell
        \startxcell[align=right,width={0.50\textwidth}] FSA-1 \stopxcell
      \stopxrow
    \stopxtablebody
    \startxtablefoot[foot]
      \startxrow
        \startxcell[align=right,width={0.50\textwidth}] Description \stopxcell
        \startxcell[align=right,width={0.50\textwidth}] ??? \stopxcell
      \stopxrow
    \stopxtablefoot
  \stopxtable
\stopplacetable

\stoptext

enter image description here

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.