We implemented support for multirows the following way:

\multirow{ncols}{width}{content}

but \multirow supports this scheme:

\multirow{ncols}[struts]{width}[offset]{content}

The attached patch adds support for the offset. It is a fileformat change.

Support for struts is not planned because this feature is only useful when using struts elsewhere in the table which is only possible using TeX-code.

OK?

regards Uwe
Index: development/FORMAT
===================================================================
--- development/FORMAT	(revision 35935)
+++ development/FORMAT	(working copy)
@@ -7,6 +7,11 @@
 
 -----------------------
 
+2010-10-31 Uwe Stöhr <uwesto...@web.de>
+	* Format incremented to 405: support for vertical offset of
+	  multirow cells
+	  new tag "mroffset" for multirow chells with an offset
+
 2010-10-13 Richard Heck <rgh...@comcast.net>
 	* Format incremented to 404: refstyle support
 	  Changed the LaTeXCommand for InsetRef from "prettyref"
Index: lib/lyx2lyx/lyx_2_0.py
===================================================================
--- lib/lyx2lyx/lyx_2_0.py	(revision 35935)
+++ lib/lyx2lyx/lyx_2_0.py	(working copy)
@@ -2381,6 +2381,55 @@
     return
 
 
+def revert_multirowOffset(document):
+    " Revert multirow cells with offset in tables to TeX-code"
+    i = 0
+    multirow = False
+    while True:
+      # cell type 3 is multirow begin cell
+      i = find_token(document.body, '<cell multirow="3" mroffset=', i)
+      if i == -1:
+          break
+      # a multirow cell with offset was found
+      multirowOffset = True
+      # remove the multirow tag, set the valignment to top
+      # the the bottom line and offset
+      document.body[i] = document.body[i].replace(' multirow="3"', ' ')
+      document.body[i] = document.body[i].replace('valignment="middle"', 'valignment="top"')
+      document.body[i] = document.body[i].replace(' bottomline="true" ', ' ')
+      document.body[i] = document.body[i].replace(' mroffset=', '')
+      begin = document.body[i].find('"')
+      document.warning("begin2: " + str(document.body[i]))
+      end = document.body[i].find('" ', begin)
+      offset = document.body[i][begin + 1:end]
+      document.body[i] = document.body[i].replace(document.body[i][begin - 1:end + 1], '')
+      document.warning("begin3: " + str(document.body[i]))
+      # write ERT to create the multirow cell
+      # use 2 rows and 2cm as default with because the multirow span
+      # and the column width is only hardly accessible
+      subst = [old_put_cmd_in_ert("\\multirow{2}{2cm}[" + offset + "]{")]
+      document.body[i + 4:i + 4] = subst
+      i = find_token(document.body, "</cell>", i)
+      if i == -1:
+           document.warning("Malformed LyX document: Could not find end of tabular cell.")
+           break
+      subst = [old_put_cmd_in_ert("}")]
+      document.body[i - 3:i - 3] = subst
+      # cell type 4 is multirow part cell
+      i = find_token(document.body, '<cell multirow="4"', i)
+      if i == -1:
+          break
+      # remove the multirow tag, set the valignment to top
+      # and remove the top line
+      document.body[i] = document.body[i].replace(' multirow="4" ', ' ')
+      document.body[i] = document.body[i].replace('valignment="middle"', 'valignment="top"')
+      document.body[i] = document.body[i].replace(' topline="true" ', ' ')
+      i = i + 1
+    if multirowOffset == True:
+        add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
+        add_to_preamble(document, ["\\usepackage{multirow}"])
+
+
 ##
 # Conversion hub
 #
@@ -2444,10 +2493,12 @@
            [401, []],
            [402, [convert_bibtexClearpage]],
            [403, [convert_flexnames]],
-           [404, [convert_prettyref]]
+           [404, [convert_prettyref]],
+           [405, []]
 ]
 
-revert =  [[403, [revert_refstyle]],
+revert =  [[404, [revert_multirowOffset]],
+           [403, [revert_refstyle]],
            [402, [revert_flexnames]],
            [401, []],
            [400, [revert_diagram]],
Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp	(revision 35935)
+++ src/Buffer.cpp	(working copy)
@@ -128,7 +128,7 @@
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-int const LYX_FORMAT = 404; // rgh: refstyle
+int const LYX_FORMAT = 405; // uwestoehr: support for multirow offset
 
 typedef map<string, bool> DepClean;
 typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
Index: src/frontends/qt4/GuiTabular.cpp
===================================================================
--- src/frontends/qt4/GuiTabular.cpp	(revision 35935)
+++ src/frontends/qt4/GuiTabular.cpp	(working copy)
@@ -89,6 +89,10 @@
 		this, SLOT(checkEnabled()));
 	connect(multirowCB, SIGNAL(clicked()),
 		this, SLOT(checkEnabled()));
+	connect(multirowOffsetED, SIGNAL(textEdited(QString)),
+		this, SLOT(checkEnabled()));
+	connect(multirowOffsetUnitCB, SIGNAL(selectionChanged(lyx::Length::UNIT)),
+		this, SLOT(checkEnabled()));
 	connect(newpageCB, SIGNAL(clicked()),
 		this, SLOT(checkEnabled()));
 	connect(headerStatusCB, SIGNAL(clicked()),
@@ -151,6 +155,7 @@
 	
 	// initialize the length validator
 	addCheckedWidget(widthED, fixedWidthColLA);
+	addCheckedWidget(multirowOffsetED, multirowOffsetLA);
 	addCheckedWidget(topspaceED, topspaceLA);
 	addCheckedWidget(bottomspaceED, bottomspaceLA);
 	addCheckedWidget(interlinespaceED, interlinespaceLA);
@@ -234,6 +239,8 @@
 	
 	multicolumnCB->setEnabled(funcEnabled(Tabular::MULTICOLUMN));
 	multirowCB->setEnabled(funcEnabled(Tabular::MULTIROW));
+	multirowOffsetED->setEnabled(multirowCB->isChecked());
+	multirowOffsetUnitCB->setEnabled(multirowCB->isChecked());
 
 	changed();
 }
@@ -458,6 +465,13 @@
 		setParam(param_str, Tabular::SET_MULTICOLUMN);
 	else
 		setParam(param_str, Tabular::UNSET_MULTICOLUMN);
+
+	// apply the multirow offset
+	string mroffset = widgetsToLength(multirowOffsetED, multirowOffsetUnitCB);
+	if (mroffset.empty())
+		mroffset = "0pt";
+	if (multirowCB->isChecked())
+		setParam(param_str, Tabular::SET_MROFFSET, mroffset);
 	//
 	if (multirowCB->isChecked())
 		setParam(param_str, Tabular::SET_MULTIROW);
@@ -571,6 +585,14 @@
 }
 
 
+static Length getMROffset(Tabular const & t, size_t cell)
+{
+	if (t.isMultiRow(cell))
+		return t.cellInfo(cell).mroffset;
+	return Length();
+}
+
+
 static docstring getAlignSpecial(Tabular const & t, size_t cell, int what)
 {
 	if (what == Tabular::SET_SPECIAL_MULTICOLUMN)
@@ -635,6 +657,17 @@
 		lengthToWidgets(widthED, widthUnitCB,
 			colwidth, default_unit);
 	}
+	Length mroffset;
+	if (multirow)
+		mroffset = getMROffset(tabular, cell);
+	string offset;
+	if (mroffset.zero())
+		multirowOffsetED->clear();
+	else {
+		offset = mroffset.asString();
+		lengthToWidgets(multirowOffsetED, multirowOffsetUnitCB,
+			offset, default_unit);
+	}
 	specialAlignmentED->setText(toqstr(special));
 	///////////////////////////////////
 
Index: src/frontends/qt4/ui/TabularUi.ui
===================================================================
--- src/frontends/qt4/ui/TabularUi.ui	(revision 35935)
+++ src/frontends/qt4/ui/TabularUi.ui	(working copy)
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>433</width>
-    <height>376</height>
+    <width>439</width>
+    <height>416</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -34,8 +34,8 @@
       <attribute name="title">
        <string>&amp;Table Settings</string>
       </attribute>
-      <layout class="QGridLayout" name="gridLayout_6">
-       <item row="0" column="0" colspan="2">
+      <layout class="QGridLayout" name="gridLayout_10">
+       <item row="0" column="0" colspan="3">
         <widget class="QGroupBox" name="GroupBox12">
          <property name="title">
           <string>Column settings</string>
@@ -231,12 +231,12 @@
          </layout>
         </widget>
        </item>
-       <item row="1" column="0">
+       <item row="1" column="0" colspan="2">
         <widget class="QGroupBox" name="groupBox">
          <property name="title">
           <string>Row setting</string>
          </property>
-         <layout class="QGridLayout" name="gridLayout_3">
+         <layout class="QGridLayout" name="gridLayout_6">
           <item row="0" column="0">
            <widget class="QCheckBox" name="multirowCB">
             <property name="toolTip">
@@ -247,10 +247,40 @@
             </property>
            </widget>
           </item>
+          <item row="1" column="0">
+           <layout class="QGridLayout" name="gridLayout_3">
+            <item row="0" column="0">
+             <widget class="QLabel" name="multirowOffsetLA">
+              <property name="text">
+               <string>&amp;Offset:</string>
+              </property>
+              <property name="buddy">
+               <cstring>widthED</cstring>
+              </property>
+             </widget>
+            </item>
+            <item row="0" column="1">
+             <widget class="QLineEdit" name="multirowOffsetED">
+              <property name="enabled">
+               <bool>true</bool>
+              </property>
+              <property name="toolTip">
+               <string>Fixed width of the column</string>
+              </property>
+              <property name="text">
+               <string/>
+              </property>
+             </widget>
+            </item>
+            <item row="0" column="2">
+             <widget class="LengthCombo" name="multirowOffsetUnitCB"/>
+            </item>
+           </layout>
+          </item>
          </layout>
         </widget>
        </item>
-       <item row="1" column="1">
+       <item row="1" column="2">
         <widget class="QGroupBox" name="groupBox_2">
          <property name="title">
           <string>Cell setting</string>
@@ -269,7 +299,7 @@
          </layout>
         </widget>
        </item>
-       <item row="2" column="0" colspan="2">
+       <item row="2" column="0" colspan="3">
         <widget class="QGroupBox" name="tabAlignmentGB">
          <property name="enabled">
           <bool>true</bool>
Index: src/insets/InsetTabular.cpp
===================================================================
--- src/insets/InsetTabular.cpp	(revision 35935)
+++ src/insets/InsetTabular.cpp	(working copy)
@@ -141,6 +141,7 @@
 	{ Tabular::MULTIROW, "multirow", false },
 	{ Tabular::SET_MULTIROW, "set-multirow", false },
 	{ Tabular::UNSET_MULTIROW, "unset-multirow", false },
+	{ Tabular::SET_MROFFSET, "set-mroffset", true },
 	{ Tabular::SET_ALL_LINES, "set-all-lines", false },
 	{ Tabular::UNSET_ALL_LINES, "unset-all-lines", false },
 	{ Tabular::SET_LONGTABULAR, "set-longtabular", false },
@@ -572,6 +573,7 @@
 	  width(cs.width),
 	  multicolumn(cs.multicolumn),
 	  multirow(cs.multirow),
+	  mroffset(cs.mroffset),
 	  alignment(cs.alignment),
 	  valignment(cs.valignment),
 	  decimal_hoffset(cs.decimal_hoffset),
@@ -601,6 +603,7 @@
 	std::swap(width, rhs.width);
 	std::swap(multicolumn, rhs.multicolumn);
 	std::swap(multirow, rhs.multirow);
+	std::swap(mroffset, rhs.mroffset);
 	std::swap(alignment, rhs.alignment);
 	std::swap(valignment, rhs.valignment);
 	std::swap(decimal_hoffset, rhs.decimal_hoffset);
@@ -1124,6 +1127,14 @@
 }
 
 
+bool Tabular::setMROffset(Cursor & cur, idx_type cell,
+		Length const & mroffset)
+{
+	cellInfo(cell).mroffset = mroffset;
+	return true;
+}
+
+
 void Tabular::setAlignSpecial(idx_type cell, docstring const & special,
 				 Tabular::Feature what)
 {
@@ -1243,6 +1254,12 @@
 }
 
 
+Length const Tabular::getMROffset(idx_type cell) const
+{
+	return cellInfo(cell).mroffset;
+}
+
+
 int Tabular::textHOffset(idx_type cell) const
 {
 	// the LaTeX Way :-(
@@ -1398,6 +1415,7 @@
 			os << "<cell"
 			   << write_attribute("multicolumn", cell_info[r][c].multicolumn)
 			   << write_attribute("multirow", cell_info[r][c].multirow)
+			   << write_attribute("mroffset", cell_info[r][c].mroffset)
 			   << write_attribute("alignment", cell_info[r][c].alignment)
 			   << write_attribute("valignment", cell_info[r][c].valignment)
 			   << write_attribute("topline", cell_info[r][c].top_line)
@@ -1507,6 +1525,7 @@
 			}
 			getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
 			getTokenValue(line, "multirow", cell_info[i][j].multirow);
+			getTokenValue(line, "mroffset", cell_info[i][j].mroffset);
 			getTokenValue(line, "alignment", cell_info[i][j].alignment);
 			getTokenValue(line, "valignment", cell_info[i][j].valignment);
 			getTokenValue(line, "topline", cell_info[i][j].top_line);
@@ -2209,7 +2228,10 @@
 		else
 			// we need to set a default value
 			os << "*";
-		os << "}{";
+		os << "}";
+		if (!getMROffset(cell).zero())
+			os << "[" << from_ascii(getMROffset(cell).asLatexString()) << "]";
+		os << "{";
 	} // end if ismultirow
 
 	if (getRotateCell(cell)) {
@@ -5042,6 +5064,10 @@
 		tabular.setMColumnPWidth(cur, cur.idx(), Length(value));
 		break;
 
+	case Tabular::SET_MROFFSET:
+		tabular.setMROffset(cur, cur.idx(), Length(value));
+		break;
+
 	case Tabular::SET_SPECIAL_COLUMN:
 	case Tabular::SET_SPECIAL_MULTICOLUMN:
 		if (value == "none")
Index: src/insets/InsetTabular.h
===================================================================
--- src/insets/InsetTabular.h	(revision 35935)
+++ src/insets/InsetTabular.h	(working copy)
@@ -193,6 +193,8 @@
 		///
 		UNSET_MULTIROW,
 		///
+		SET_MROFFSET,
+		///
 		SET_ALL_LINES,
 		///
 		UNSET_ALL_LINES,
@@ -405,6 +407,8 @@
 	///
 	bool setMColumnPWidth(Cursor &, idx_type, Length const &);
 	///
+	bool setMROffset(Cursor &, idx_type, Length const &);
+	///
 	void setAlignSpecial(idx_type cell, docstring const & special,
 			     Feature what);
 	///
@@ -416,6 +420,8 @@
 	///
 	Length const getPWidth(idx_type cell) const;
 	///
+	Length const getMROffset(idx_type cell) const;
+	///
 	int textHOffset(idx_type cell) const;
 	///
 	int textVOffset(idx_type cell) const;
@@ -562,6 +568,8 @@
 		///
 		int multirow;
 		///
+		Length mroffset;
+		///
 		LyXAlignment alignment;
 		///
 		VAlignment valignment;

Reply via email to