>
> Hi,
>
> Since some time I'm contemplating implementing booktabs a.k.a. tableaux
> support for 1.3.x. Would that have a chance to go in, if properly done? I.e.
> are any new features allowed into 1.3.x? I might have asked that before, but
> have forgotten the answer since :) *
>
> I'm thinking of adding a per-table "Book-style table" checkbox which will
> limit what you can do to the table - i.e. no vertical lines, as well as
> adding support for top/mid/bottom rule and cmidrule. Since this would rather
> trivially extend the file format keeping it 100% upward compatible, it needs
> a `cat`-style up-lyxconvert, and a reasonably trivial down-lyxconvert which
> I'm willing to write as well - I'm thinking it would simply downgrade the
> "nice" rules into obnoxious "standard" ones.
>
> Comments/rants/flames welcome.
>
> Cheers, Kuba Ober
>
> * and I'm too lazy to look for it in the archives. Maybe with some external
> coercion :)
>
Here's a limited patch for 1.4cvs. It has several limitations:
* As Alfredo wrote, tables don't work currently in 1.4cvs, so they're a bit hard to test :)
* The UI patch is only for Qt, not XForms. And is pretty minimalist: a "Booktabs" check box in the table dialog. We'd need also a global preference -- not to mention renaming it.
* Likewise, I named the flag "booktabs" in the source (isBookTabs(), <feature booktabs="true">, etc.). I think a better name is needed here also (tableau?)
* Vertical bars are not disabled. Should they? And they're systematically removed at creation time (yay! ;-))
* The "booktabs" class is added as a feature, but the package's existence not checked.
* No doc patch.
Regards,
Yves
[I left the "interesting" part of the patch readable and gziped the src/frontends/qt2/ui/QTabularDialogBase.ui one]
Index: src/LaTeXFeatures.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/LaTeXFeatures.C,v retrieving revision 1.103 diff -u -p -r1.103 LaTeXFeatures.C --- src/LaTeXFeatures.C 2004/01/21 17:52:05 1.103 +++ src/LaTeXFeatures.C 2004/01/29 16:54:32 @@ -191,7 +191,8 @@ char const * simplefeatures[] = { "wasy", "dvipost", "fancybox", - "calc" + "calc", + "booktabs" }; int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *); Index: src/tabular.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/tabular.C,v retrieving revision 1.202 diff -u -p -r1.202 tabular.C --- src/tabular.C 2004/01/26 10:13:09 1.202 +++ src/tabular.C 2004/01/29 16:54:34 @@ -303,9 +303,9 @@ LyXTabular::cellstruct::cellstruct(Buffe multicolumn = LyXTabular::CELL_NORMAL; alignment = LYX_ALIGN_CENTER; valignment = LYX_VALIGN_TOP; - top_line = true; + top_line = false; bottom_line = false; - left_line = true; + left_line = false; right_line = false; usebox = BOX_NONE; rotate = false; @@ -314,7 +314,7 @@ LyXTabular::cellstruct::cellstruct(Buffe LyXTabular::rowstruct::rowstruct() { - top_line = true; + top_line = false; bottom_line = false; ascent_of_row = 0; descent_of_row = 0; @@ -328,7 +328,7 @@ LyXTabular::rowstruct::rowstruct() LyXTabular::columnstruct::columnstruct() { - left_line = true; + left_line = false; right_line = false; alignment = LYX_ALIGN_CENTER; valignment = LYX_VALIGN_TOP; @@ -362,12 +362,11 @@ void LyXTabular::init(BufferParams const column_info.reserve(10); cell_info.reserve(100); fixCellNums(); - for (int i = 0; i < rows_; ++i) - cell_info[i].back().right_line = true; row_info.back().bottom_line = true; + row_info.front().top_line = true; row_info.front().bottom_line = true; - column_info.back().right_line = true; is_long_tabular = false; + is_booktabs = false; rotate = false; } @@ -380,7 +379,6 @@ void LyXTabular::fixCellNums() cell_info[i][j].inset.setDrawFrame(InsetText::LOCKED); cell_info[i][j].cellno = cellno++; } - cell_info[i].back().right_line = true; } set_row_column_number_info(); @@ -1087,6 +1085,7 @@ void LyXTabular::write(Buffer const & bu // global longtable options os << "<features" << write_attribute("rotate", rotate) + << write_attribute("booktabs", is_booktabs) << write_attribute("islongtable", is_long_tabular) << write_attribute("firstHeadTopDL", endfirsthead.topDL) << write_attribute("firstHeadBottomDL", endfirsthead.bottomDL) @@ -1253,6 +1252,7 @@ void LyXTabular::read(Buffer const & buf return; } getTokenValue(line, "rotate", rotate); + getTokenValue(line, "booktabs", is_booktabs); getTokenValue(line, "islongtable", is_long_tabular); // compatibility read for old longtable options. Now we can make any // row part of the header/footer type we want before it was strict @@ -1433,6 +1433,18 @@ int LyXTabular::unsetMultiColumn(int cel } +void LyXTabular::setBookTabs(bool what) +{ + is_booktabs = what; +} + + +bool LyXTabular::isBookTabs() const +{ + return is_booktabs; +} + + void LyXTabular::setLongTabular(bool what) { is_long_tabular = what; @@ -1716,6 +1728,48 @@ bool LyXTabular::isPartOfMultiColumn(int } +void LyXTabular::TeXCMidRule(ostream & os, int cell) const +{ + int left_column = column_of_cell(cell) + 1; + int right_column = right_column_of_cell(cell) + 1; + + if (!isBookTabs()) { + os << "\\cline{" + << left_column + << '-' + << right_column + << "} "; + } else { + char const *trim = ""; + /* + Trimming cases: + ========== no trimming + | | | | + ===+--+--+ right + | | | | + +--+==+--+ right & left + | | | | + +--+--+=== left + */ + if (left_column == 1) { + if (right_column != columns_) + trim = "(r)"; + } else { + if (right_column != columns_) + trim = "(lr)"; + else + trim = "(l)"; + } + os << "\\cmidrule" + << trim + << "{" + << left_column + << '-' + << right_column + << "} "; + } +} + int LyXTabular::TeXTopHLine(ostream & os, int row) const { if (row < 0 || row >= rows_) @@ -1730,15 +1784,19 @@ int LyXTabular::TeXTopHLine(ostream & os ++tmp; } if (tmp == n - fcell) { - os << "\\hline "; + if (isBookTabs()) { + if (row == 0) { + os << "\\toprule "; + } else { + os << "\\midrule "; + } + } else { + os << "\\hline "; + } } else if (tmp) { for (int i = fcell; i < n; ++i) { if (topLine(i)) { - os << "\\cline{" - << column_of_cell(i) + 1 - << '-' - << right_column_of_cell(i) + 1 - << "} "; + TeXCMidRule(os, i); } } } else { @@ -1763,15 +1821,19 @@ int LyXTabular::TeXBottomHLine(ostream & ++tmp; } if (tmp == n - fcell) { - os << "\\hline"; + if (!isBookTabs()) { + os << "\\hline"; + } else { + // no accessor? + if (row == rows_ - 1) + os << "\\bottomrule "; + else + os << "\\midrule "; + } } else if (tmp) { for (int i = fcell; i < n; ++i) { if (bottomLine(i)) { - os << "\\cline{" - << column_of_cell(i) + 1 - << '-' - << right_column_of_cell(i) + 1 - << "} "; + TeXCMidRule(os, i); } } } else { @@ -2569,6 +2631,8 @@ void LyXTabular::validate(LaTeXFeatures features.require("NeedTabularnewline"); if (isLongTabular()) features.require("longtable"); + if (isBookTabs()) + features.require("booktabs"); if (needRotating()) features.require("rotating"); for (int cell = 0; cell < numberofcells; ++cell) { Index: src/tabular.h =================================================================== RCS file: /cvs/lyx/lyx-devel/src/tabular.h,v retrieving revision 1.88 diff -u -p -r1.88 tabular.h --- src/tabular.h 2004/01/26 10:13:10 1.88 +++ src/tabular.h 2004/01/29 16:54:34 @@ -124,6 +124,9 @@ public: /// SET_SPECIAL_MULTI, /// + SET_BOOKTABS, + UNSET_BOOKTABS, + /// LAST_ACTION }; /// @@ -306,6 +309,10 @@ public: /// int right_column_of_cell(int cell) const; /// + void setBookTabs(bool); + /// + bool isBookTabs() const; + /// void setLongTabular(bool); /// bool isLongTabular() const; @@ -490,6 +497,8 @@ public: int width_of_tabular; /// bool rotate; + /// + bool is_booktabs; // // for long tabulars // @@ -562,6 +571,9 @@ public: OutputParams const &) const; private: + /// output \\cline or \\cmidrule, used by both TeXTopHLine and TeXBottomHLine + void TeXCMidRule(std::ostream &, int cell) const; + /// /// renumber cells after structural changes void fixCellNums(); }; Index: src/frontends/controllers/ControlTabular.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/frontends/controllers/ControlTabular.C,v retrieving revision 1.19 diff -u -p -r1.19 ControlTabular.C --- src/frontends/controllers/ControlTabular.C 2003/10/06 15:42:46 1.19 +++ src/frontends/controllers/ControlTabular.C 2004/01/29 16:54:35 @@ -218,3 +218,12 @@ void ControlTabular::longTabular(bool ye else set(LyXTabular::UNSET_LONGTABULAR); } + + +void ControlTabular::bookTabs(bool yes) +{ + if (yes) + set(LyXTabular::SET_BOOKTABS); + else + set(LyXTabular::UNSET_BOOKTABS); +} Index: src/frontends/controllers/ControlTabular.h =================================================================== RCS file: /cvs/lyx/lyx-devel/src/frontends/controllers/ControlTabular.h,v retrieving revision 1.10 diff -u -p -r1.10 ControlTabular.h --- src/frontends/controllers/ControlTabular.h 2003/10/06 15:42:46 1.10 +++ src/frontends/controllers/ControlTabular.h 2004/01/29 16:54:35 @@ -67,6 +67,8 @@ public: void longTabular(bool yes); + void bookTabs(bool yes); + private: /// int active_cell_; Index: src/frontends/qt2/QTabular.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/frontends/qt2/QTabular.C,v retrieving revision 1.29 diff -u -p -r1.29 QTabular.C --- src/frontends/qt2/QTabular.C 2003/10/06 15:42:52 1.29 +++ src/frontends/qt2/QTabular.C 2004/01/29 16:54:35 @@ -57,6 +57,7 @@ void QTabular::build_dialog() bcview().addReadOnly(dialog_->borderUnsetPB); bcview().addReadOnly(dialog_->borders); bcview().addReadOnly(dialog_->longTabularCB); + bcview().addReadOnly(dialog_->bookTabsCB); bcview().addReadOnly(dialog_->headerStatusCB); bcview().addReadOnly(dialog_->headerBorderAboveCB); bcview().addReadOnly(dialog_->headerBorderBelowCB); @@ -223,6 +224,8 @@ void QTabular::update_contents() dialog_->hAlignCB->setEnabled(true); dialog_->vAlignCB->setEnabled(!pwidth.zero()); + + dialog_->bookTabsCB->setChecked(tabular.isBookTabs()); if (!tabular.isLongTabular()) { dialog_->headerStatusCB->setChecked(false); Index: src/frontends/qt2/QTabularDialog.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/frontends/qt2/QTabularDialog.C,v retrieving revision 1.20 diff -u -p -r1.20 QTabularDialog.C --- src/frontends/qt2/QTabularDialog.C 2003/11/20 01:22:51 1.20 +++ src/frontends/qt2/QTabularDialog.C 2004/01/29 16:54:36 @@ -121,6 +121,13 @@ void QTabularDialog::multicolumn_clicked } +void QTabularDialog::bookTabs_clicked() +{ + form_->controller().bookTabs(bookTabsCB->isChecked()); + form_->changed(); +} + + void QTabularDialog::rotateTabular() { form_->controller().rotateTabular(rotateTabularCB->isChecked()); Index: src/frontends/qt2/QTabularDialog.h =================================================================== RCS file: /cvs/lyx/lyx-devel/src/frontends/qt2/QTabularDialog.h,v retrieving revision 1.9 diff -u -p -r1.9 QTabularDialog.h --- src/frontends/qt2/QTabularDialog.h 2003/09/07 01:45:38 1.9 +++ src/frontends/qt2/QTabularDialog.h 2004/01/29 16:54:36 @@ -35,6 +35,7 @@ protected slots: virtual void topBorder_changed(); virtual void bottomBorder_changed(); virtual void multicolumn_clicked(); + virtual void bookTabs_clicked(); virtual void rotateTabular(); virtual void rotateCell(); virtual void hAlign_changed(int align);
lyx14-booktabs-qtui.diff.gz
Description: GNU Zip compressed data