JelteF / PyLaTeX

A Python library for creating LaTeX files
https://jeltef.github.io/PyLaTeX/
MIT License
2.24k stars 287 forks source link

Multirow / Mulitcolumn failure #349

Open riklopfer opened 2 years ago

riklopfer commented 2 years ago

pulled a single table from the examples page, and it generates an invalid tex file. Appears to be missing \usepackage{multirow} ?

import sys

from pylatex import Document, Section, Tabular, MultiColumn, MultiRow

def test_example3():
    doc = Document("broken")
    section = Section('Multirow Test')

    table3 = Tabular('|c|c|c|')
    table3.add_hline()
    table3.add_row((MultiColumn(2, align='|c|',
                                data=MultiRow(2, data='multi-col-row')), 'X'))
    table3.add_row((MultiColumn(2, align='|c|', data=''), 'X'))
    table3.add_hline()
    table3.add_row(('X', 'X', 'X'))
    table3.add_hline()

    section.append(table3)

    doc.append(section)

    doc.generate_pdf(clean_tex=False)

if __name__ == '__main__':
    sys.exit(test_example3())

There is quite a bit of output, but here are what I believe to be the important parts

stdout,

! Undefined control sequence.
\@sharp ->\multirow 
                    {2}{*}{multi{-}col{-}row}
l.16 ...}{|c|}{\multirow{2}{*}{multi{-}col{-}row}}
                                                  &X\\%

Package lastpage Warning: Rerun to get the references right on input line 24.

broken.log

! Undefined control sequence.
\@sharp ->\multirow 
                    {2}{*}{multi{-}col{-}row}
l.16 ...}{|c|}{\multirow{2}{*}{multi{-}col{-}row}}
                                                  &X\\%
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

broken.tex

\documentclass{article}%
\usepackage[T1]{fontenc}%
\usepackage[utf8]{inputenc}%
\usepackage{lmodern}%
\usepackage{textcomp}%
\usepackage{lastpage}%
%
%
%
\begin{document}%
\normalsize%
\section{Multirow Test}%
\label{sec:MultirowTest}%
\begin{tabular}{|c|c|c|}%
\hline%
\multicolumn{2}{|c|}{\multirow{2}{*}{multi{-}col{-}row}}&X\\%
\multicolumn{2}{|c|}{}&X\\%
\hline%
X&X&X\\%
\hline%
\end{tabular}

%
\end{document}