diff --git a/src/Counters.h b/src/Counters.h index a195889e31..ce122c4140 100644 --- a/src/Counters.h +++ b/src/Counters.h @@ -172,6 +172,10 @@ public: bool isSubfloat() const { return subfloat_; } /// Set the state variable indicating whether we are in a subfloat. void isSubfloat(bool s) { subfloat_ = s; } + /// Are we in a longtable? + bool isLongtable() const { return longtable_; } + /// Set the state variable indicating whether we are in a longtable. + void isLongtable(bool s) { longtable_ = s; } /// \name refstepcounter // @{ @@ -225,6 +229,8 @@ private: std::string current_float_; /// Are we in a subfloat? bool subfloat_; + /// Are we in a longtable? + bool longtable_; /// Used to keep track of active counters. std::vector counter_stack_; /// Same, but for last layout. diff --git a/src/insets/InsetCaption.cpp b/src/insets/InsetCaption.cpp index 2303a1d82a..f1f0983810 100644 --- a/src/insets/InsetCaption.cpp +++ b/src/insets/InsetCaption.cpp @@ -404,7 +404,9 @@ void InsetCaption::updateBuffer(ParIterator const & it, UpdateType utype) docstring const labelstring = isAscii(lstring) ? master.B_(to_ascii(lstring)) : lstring; if (cnts.hasCounter(counter)) { - cnts.step(counter, utype); + // for longtables, we step the counter upstream + if (!cnts.isLongtable()) + cnts.step(counter, utype); sec = cnts.theCounter(counter, lang); } if (labelstring != master.B_("standard")) { diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index b633c492e1..f89c34a285 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -3897,8 +3897,12 @@ void InsetTabular::updateBuffer(ParIterator const & it, UpdateType utype) // In a longtable, tell captions what the current float is Counters & cnts = buffer().masterBuffer()->params().documentClass().counters(); string const saveflt = cnts.current_float(); - if (tabular.is_long_tabular) + if (tabular.is_long_tabular) { cnts.current_float("table"); + // in longtables, we only step the counter once + cnts.step(from_ascii("table"), utype); + cnts.isLongtable(true); + } ParIterator it2 = it; it2.forwardPos(); @@ -3907,8 +3911,10 @@ void InsetTabular::updateBuffer(ParIterator const & it, UpdateType utype) buffer().updateBuffer(it2, utype); //reset afterwards - if (tabular.is_long_tabular) + if (tabular.is_long_tabular) { cnts.current_float(saveflt); + cnts.isLongtable(false); + } }