2

I recently got into LyX and I’m getting along quite well.

The only thing that bothers me is that LyX’s table feature produces really sloppy-looking tables by default, i.e. double borders and stuff like that.

I would love to tell LyX to use the tabularx environment by default for the tables I enter via the GUI element, so I can get tables with 100% width matching the justified paragraphs. Concerning the borders, I would like to remove all of them but a \toprule above and beneath the first row of the table and a \bottomrule beneath the last row. These features are added by the ctable package which is included in my document preamble. Is there any way I can achieve these things without performing crazy stuff like regex?

Thanks in advance!

2

write into the preamble of your document (document->settings->preamble)

\usepackage{array}
\def\tabular{%
 \setlength\dimen@{\linewidth}%
   \edef\@halignto{to\the\dimen@}\@tabular}
\newcolumntype{C}{@{\extracolsep{\fill}}c}


then all tables are by default converted into tabular*. Choose for the first column the column type C or write alternetively the definition @{\extracolsep{\fill}}c for the first column via the tabular menu

  • 1
    This seems to be a good starting point, but instead of evenly spacing out the colums of my 3-column-table, this just adds a fourth, empty column covering the remaining text area. Note that the author line in the heading is awkwardly aligned as well. – Christoph Nov 15 '11 at 18:47
  • with tabular* you can not stretch all columns. See edited example. However, I suppose, that you want the tabularx instead of tabular* – user2478 Nov 15 '11 at 19:03
  • Thank you for your comment, it was really the tabularx environment I was looking for. I used \begin{tabularx}{\textwidth}{XXX} without your custom preamble to create the effect I was looking for. But nevertheless, LyX won’t format tables inserted via the GUI this way and I couldn’t wrap my head around the border issue, yet. Seems like I will stick to entering code for my tables instead of using the GUI. If only one could use CSS to manipulate the PDF output, I would know exactly what to do! But anyways, thank you very much for your help. – Christoph Nov 15 '11 at 19:44
1

I guess you could perform the following two global replacement operations:

  • replace all "\end{tabular}" strings with "\end{tabular*}"
  • replace all "\begin{tabular}{" strings with "\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}"

Regarding the replacment of the \hline commands with \toprule, \midrule, and \bottomrule: Whether it's possible to do a global search-and-replace will depend greatly on how you've entered the \hline commands so far. Without detailed knowledge of this aspect, I can't give a suggestion for how to perform this step.

  • Thank you for your answer but I think you misinterpreted / I misformulated my question. I can of course enter the right TeX code to produce the tables the way I want them to look, but my intention is to „tell“ LyX to use this code for the tables I entered via the GUI automatically, i.e. without having to enter any TeX code. I will update my question to reflect these goals. – Christoph Nov 15 '11 at 18:22
  • Shouldn't it be tabularx instead of tabular*? – Dmitri Nesteruk Oct 5 '16 at 14:12
  • 1
    @DmitriNesteruk - Not really. :-) The tabularx and tabular* environments both serve to generate tables with a pre-set width (often \textwidth, as in the present case), but they achieve the goal in different ways. The former achieves the goal by changing the widths of certain columns -- those of type X, to be precise -- whereas the latter operates by changing the amount of intercolumn whitespace (that's what @{\extracolsep{\fill}}directive is all about). It's a bit confusing, honestly, because the posting was edited to focus on tabularx, but only after I had posted my answer... – Mico Oct 5 '16 at 14:25

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.