From 4a9cd3426916465ec8d18ffa7dd1d57e160ffa2c Mon Sep 17 00:00:00 2001 From: milde Date: Thu, 30 Dec 2010 23:00:58 +0000 Subject: [PATCH] Apply [ 3148141 ] fix multicolumn support. Correct width, when a colspanning cell has more than one paragraph. Thanks to Wolfgang Scherer. git-svn-id: https://docutils.svn.sourceforge.net/svnroot/docutils/trunk/docutils@6508 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- HISTORY.txt | 2 + docutils/writers/latex2e/__init__.py | 15 +++- test/functional/expected/standalone_rst_latex.tex | 95 +++++++++++++++++++---- test/functional/expected/standalone_rst_xetex.tex | 4 +- test/functional/input/data/tables_latex.txt | 20 +++++ test/functional/input/standalone_rst_latex.txt | 1 + 6 files changed, 119 insertions(+), 18 deletions(-) create mode 100644 test/functional/input/data/tables_latex.txt diff --git a/HISTORY.txt b/HISTORY.txt index 968711ff1..41ee7a5cb 100644 --- a/HISTORY.txt +++ b/HISTORY.txt @@ -54,6 +54,8 @@ Changes Since 0.7 line-quotes with class argument "language-". - 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/writers/latex2e/__init__.py b/docutils/writers/latex2e/__init__.py index 9ea511177..099b36a23 100644 --- a/docutils/writers/latex2e/__init__.py +++ b/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/test/functional/expected/standalone_rst_latex.tex b/test/functional/expected/standalone_rst_latex.tex index 4db84f276..e016b78c3 100644 --- a/test/functional/expected/standalone_rst_latex.tex +++ b/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/test/functional/expected/standalone_rst_xetex.tex b/test/functional/expected/standalone_rst_xetex.tex index 32d03abca..8a3c87452 100644 --- a/test/functional/expected/standalone_rst_xetex.tex +++ b/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/test/functional/input/data/tables_latex.txt b/test/functional/input/data/tables_latex.txt new file mode 100644 index 000000000..8e74b438c --- /dev/null +++ b/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/test/functional/input/standalone_rst_latex.txt b/test/functional/input/standalone_rst_latex.txt index e0dccf219..7078faec2 100644 --- a/test/functional/input/standalone_rst_latex.txt +++ b/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 -- 2.11.4.GIT