summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docutils/HISTORY.txt2
-rw-r--r--docutils/docutils/writers/latex2e/__init__.py15
-rw-r--r--docutils/test/functional/expected/standalone_rst_latex.tex95
-rw-r--r--docutils/test/functional/expected/standalone_rst_xetex.tex4
-rw-r--r--docutils/test/functional/input/data/tables_latex.txt20
-rw-r--r--docutils/test/functional/input/standalone_rst_latex.txt1
6 files changed, 119 insertions, 18 deletions
diff --git a/docutils/HISTORY.txt b/docutils/HISTORY.txt
index 968711ff1..41ee7a5cb 100644
--- a/docutils/HISTORY.txt
+++ b/docutils/HISTORY.txt
@@ -54,6 +54,8 @@ Changes Since 0.7
line-quotes with class argument "language-<language tag>".
- Fix [ 3095603 ] wrong quotes output for russian and other languages.
- Convert image URI to a local file path.
+ - Apply [ 3148141 ] fix multicolumn support when a colspanning cell
+ has more than one paragraph (Wolfgang Scherer).
* docutils/writers/xetex/__init__.py
diff --git a/docutils/docutils/writers/latex2e/__init__.py b/docutils/docutils/writers/latex2e/__init__.py
index 9ea511177..099b36a23 100644
--- a/docutils/docutils/writers/latex2e/__init__.py
+++ b/docutils/docutils/writers/latex2e/__init__.py
@@ -825,6 +825,13 @@ class Table(object):
"""Return columnwidth for current cell (not multicell)."""
return '%.2f\\DUtablewidth' % self._col_width[self._cell_in_row-1]
+ def get_multicolumn_width(self, start, len_):
+ """Return sum of columnwidths for multicell."""
+ mc_width = sum(width
+ for width in (self._col_width[start + co - 1]
+ for co in range (len_)))
+ return '{0:.2f}\\DUtablewidth'.format(mc_width)
+
def get_caption(self):
if not self.caption:
return ''
@@ -1913,8 +1920,12 @@ class LaTeXTranslator(nodes.NodeVisitor):
else:
bar1 = ''
count = node['morecols'] + 1
- self.out.append('\\multicolumn{%d}{%sl%s}{' %
- (count, bar1, self.active_table.get_vertical_bar()))
+ self.out.append('\\multicolumn{%d}{%sp{%s}%s}{' %
+ (count, bar1,
+ self.active_table.get_multicolumn_width(
+ self.active_table.get_entry_number(),
+ count),
+ self.active_table.get_vertical_bar()))
self.context.append('}')
else:
self.context.append('')
diff --git a/docutils/test/functional/expected/standalone_rst_latex.tex b/docutils/test/functional/expected/standalone_rst_latex.tex
index 4db84f276..e016b78c3 100644
--- a/docutils/test/functional/expected/standalone_rst_latex.tex
+++ b/docutils/test/functional/expected/standalone_rst_latex.tex
@@ -1449,7 +1449,7 @@ This table has a cell spanning two columns:
\setlength{\DUtablewidth}{\linewidth}
\begin{longtable}[c]{|p{0.075\DUtablewidth}|p{0.075\DUtablewidth}|p{0.086\DUtablewidth}|}
\hline
-\multicolumn{2}{|l|}{\textbf{%
+\multicolumn{2}{|p{0.15\DUtablewidth}|}{\textbf{%
Inputs
}} & \textbf{%
Output
@@ -1465,7 +1465,7 @@ A or B
\hline
\endfirsthead
\hline
-\multicolumn{2}{|l|}{\textbf{%
+\multicolumn{2}{|p{0.15\DUtablewidth}|}{\textbf{%
Inputs
}} & \textbf{%
Output
@@ -1805,14 +1805,81 @@ This is a \DUroletitlereference{\DUrole{custom-title-reference}{customized title
\end{itemize}
+
+%___________________________________________________________________________
+
+\subsection*{\phantomsection%
+ 3.2~~~More Tables%
+ \addcontentsline{toc}{subsection}{3.2~~~More Tables}%
+ \label{more-tables}%
+}
+
+A multicolumn table with multi-paragraph rowspanning cells:
+
+\leavevmode
+\setlength{\DUtablewidth}{\linewidth}
+\begin{longtable}[c]{|p{0.133\DUtablewidth}|p{0.179\DUtablewidth}|p{0.179\DUtablewidth}|p{0.110\DUtablewidth}|p{0.121\DUtablewidth}|p{0.145\DUtablewidth}|}
+\hline
+
+test
+ &
+\textbf{bold hd}
+ & \multicolumn{3}{p{0.41\DUtablewidth}|}{
+multicolumn 1
+
+With a second paragraph
+} &
+\emph{emph hd}
+ \\
+\hline
+\multicolumn{2}{|p{0.31\DUtablewidth}|}{
+multicolumn 2
+
+With a second paragraph
+} &
+cell
+ &
+cell
+ &
+cell
+ &
+cell
+ \\
+\hline
+
+cell
+ & \multicolumn{2}{p{0.36\DUtablewidth}|}{
+multicolumn 3 (one line,
+but very very very very
+very looooong)
+} &
+cell
+ &
+cell
+ &
+cell
+ \\
+\hline
+
+cell
+ &
+cell
+ &
+cell
+ & \multicolumn{3}{p{0.38\DUtablewidth}|}{
+Short multicolumn 4
+} \\
+\hline
+\end{longtable}
+
% This file is used by the standalone_rst_latex test.
%___________________________________________________________________________
\subsection*{\phantomsection%
- 3.2~~~Option lists%
- \addcontentsline{toc}{subsection}{3.2~~~Option lists}%
+ 3.3~~~Option lists%
+ \addcontentsline{toc}{subsection}{3.3~~~Option lists}%
\label{id23}%
}
@@ -1851,8 +1918,8 @@ is contained in a quote
%___________________________________________________________________________
\subsection*{\phantomsection%
- 3.3~~~Monospaced non-alphanumeric characters%
- \addcontentsline{toc}{subsection}{3.3~~~Monospaced non-alphanumeric characters}%
+ 3.4~~~Monospaced non-alphanumeric characters%
+ \addcontentsline{toc}{subsection}{3.4~~~Monospaced non-alphanumeric characters}%
\label{monospaced-non-alphanumeric-characters}%
}
@@ -1871,8 +1938,8 @@ width as the third line.
%___________________________________________________________________________
\subsection*{\phantomsection%
- 3.4~~~Non-ASCII characters%
- \addcontentsline{toc}{subsection}{3.4~~~Non-ASCII characters}%
+ 3.5~~~Non-ASCII characters%
+ \addcontentsline{toc}{subsection}{3.5~~~Non-ASCII characters}%
\label{non-ascii-characters}%
}
@@ -2291,8 +2358,8 @@ to the document options or use a different font package.
%___________________________________________________________________________
\subsection*{\phantomsection%
- 3.5~~~Encoding special chars%
- \addcontentsline{toc}{subsection}{3.5~~~Encoding special chars}%
+ 3.6~~~Encoding special chars%
+ \addcontentsline{toc}{subsection}{3.6~~~Encoding special chars}%
\label{encoding-special-chars}%
}
@@ -2364,8 +2431,8 @@ greater-than and bar, < | >, except for typewriter font \DUroletitlereference{cm
%___________________________________________________________________________
\subsection*{\phantomsection%
- 3.6~~~Hyperlinks and -targets%
- \addcontentsline{toc}{subsection}{3.6~~~Hyperlinks and -targets}%
+ 3.7~~~Hyperlinks and -targets%
+ \addcontentsline{toc}{subsection}{3.7~~~Hyperlinks and -targets}%
\label{hyperlinks-and-targets}%
}
@@ -2414,8 +2481,8 @@ See \hyperref[hypertarget-in-plain-text]{hypertarget in plain text},
%___________________________________________________________________________
\subsection*{\phantomsection%
- 3.7~~~External references%
- \addcontentsline{toc}{subsection}{3.7~~~External references}%
+ 3.8~~~External references%
+ \addcontentsline{toc}{subsection}{3.8~~~External references}%
\label{external-references}%
}
diff --git a/docutils/test/functional/expected/standalone_rst_xetex.tex b/docutils/test/functional/expected/standalone_rst_xetex.tex
index 32d03abca..8a3c87452 100644
--- a/docutils/test/functional/expected/standalone_rst_xetex.tex
+++ b/docutils/test/functional/expected/standalone_rst_xetex.tex
@@ -1451,7 +1451,7 @@ This table has a cell spanning two columns:
\setlength{\DUtablewidth}{\linewidth}
\begin{longtable}[c]{|p{0.075\DUtablewidth}|p{0.075\DUtablewidth}|p{0.086\DUtablewidth}|}
\hline
-\multicolumn{2}{|l|}{\textbf{%
+\multicolumn{2}{|p{0.15\DUtablewidth}|}{\textbf{%
Inputs
}} & \textbf{%
Output
@@ -1467,7 +1467,7 @@ A or B
\hline
\endfirsthead
\hline
-\multicolumn{2}{|l|}{\textbf{%
+\multicolumn{2}{|p{0.15\DUtablewidth}|}{\textbf{%
Inputs
}} & \textbf{%
Output
diff --git a/docutils/test/functional/input/data/tables_latex.txt b/docutils/test/functional/input/data/tables_latex.txt
new file mode 100644
index 000000000..8e74b438c
--- /dev/null
+++ b/docutils/test/functional/input/data/tables_latex.txt
@@ -0,0 +1,20 @@
+More Tables
+-----------
+
+A multicolumn table with multi-paragraph rowspanning cells:
+
++----------+--------------+---------------------------------+-----------+
+| test | **bold hd** | multicolumn 1 | *emph hd* |
+| | | | |
+| | | With a second paragraph | |
++----------+--------------+--------------+--------+---------+-----------+
+| multicolumn 2 | cell | cell | cell | cell |
+| | | | | |
+| With a second paragraph | | | | |
++----------+--------------+--------------+--------+---------+-----------+
+| cell | multicolumn 3 (one line, | cell | cell | cell |
+| | but very very very very | | | |
+| | very looooong) | | | |
++----------+--------------+--------------+--------+---------+-----------+
+| cell | cell | cell | Short multicolumn 4 |
++----------+--------------+--------------+------------------------------+
diff --git a/docutils/test/functional/input/standalone_rst_latex.txt b/docutils/test/functional/input/standalone_rst_latex.txt
index e0dccf219..7078faec2 100644
--- a/docutils/test/functional/input/standalone_rst_latex.txt
+++ b/docutils/test/functional/input/standalone_rst_latex.txt
@@ -13,6 +13,7 @@ Test syntax elements which may cause trouble for the LaTeX writer but might
not need to be tested with other writers (e.g. the HTML writer).
.. include:: data/custom_roles_latex.txt
+.. include:: data/tables_latex.txt
.. include:: data/option_lists.txt
.. include:: data/nonalphanumeric.txt
.. include:: data/unicode.txt