3

I want to insert preformatted text into a table. I tried to accomplish this with \startlines but the command shows no effect in tables. It is possible with \break but this is no real solution.

How can I insert preformatted text inside tables?

MWE:

\starttext

\startlines
multi
lines
work
\stoplines

\bTABLE
  \bTR
    \bTD
    \startlines
multi
lines
work
    \stoplines
    \eTD
    \bTD
multi\break
lines\break
work
    \eTD
  \eTR
\eTABLE

\stoptext
7

The problem with natural tables is that each cell saves the content before the lines environment can see the text as individual lines.

You can work around this when you put the the text for the lines environment in a buffer. When you load now the content of the buffer in the table the text stays in separate lines.

\starttext

\startbuffer[lines]
multi
lines
work
\stopbuffer

\bTABLE
    \bTR
        \bTD
            \startlines
            \getbuffer[lines]
            \stoplines
        \eTD
    \eTR
\eTABLE

\stoptext

When you have only a few lines of text you can skip the lines environment and use the \\ command to mark the end of each text line in the table cells.

\starttext

\bTABLE
    \bTR
        \bTD
            multi\\
            lines\\
            work
        \eTD
    \eTR
\eTABLE

\stoptext

Another possibility is to replace natural tables with the xtable environment which can handle lines without problems because it uses a different method to calculate the table dimensions.

\starttext

\startxtable
    \startxrow
        \startxcell
            \startlines
            multi
            lines
            work
            \stoplines
        \stopxcell
    \stopxrow
\stopxtable

\stoptext

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.