# Use tabularx in LyX instead of default tabular

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?

-
 Welcome to TeX.sx! A tip: You can use backticks  to mark your inline code as I did in my edit. – Joseph Wright♦ Nov 15 '11 at 17:15

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

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

-
 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* – Herbert 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