Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grid_tables with multicol/multirow too wide #9140

Closed
DavidNemeskey opened this issue Oct 16, 2023 · 6 comments
Closed

grid_tables with multicol/multirow too wide #9140

DavidNemeskey opened this issue Oct 16, 2023 · 6 comments
Labels

Comments

@DavidNemeskey
Copy link

DavidNemeskey commented Oct 16, 2023

Explain the problem.

I am creating beamer presentations from pandoc markdown. I tried to add a table with multicol + multirow, using the grid_tables format (which is the only one that supports these features if I understand correctly). Unfortunately, the tables generated are way too wide. I used two of the examples from the documentation. In the first one (with multicol), the first column is way too wide, unnecessarily so. In the second (multicol + multirow), the table is so wide that it hangs off the slide on the right, even though all the content fits comfortably on the page.

pandoc -t beamer -o output.pdf --slide-level 2 pandoc_table.md

The MWE is here: pandoc_table.md.

This is how it looks like:
grid_table_hanging_off

Pandoc version?

Pandoc: 3.1.8
OS: KDE Neon (6.2.0-34-generic #34~22.04.1-Ubuntu x86_64)
Texlive: 2021.202204-1

@chagmed
Copy link

chagmed commented Oct 17, 2023

Alas, grid_tables makes me feel utterly defeated. I can code in several languages, am very comfortable with many complex tech stacks, but I cannot for the life of me figure out how to write well-behaved grid tables consistently and predictably. Not good when examples from the docs don't work.

@jgm
Copy link
Owner

jgm commented Oct 17, 2023

Yes, definitely problematic, we'll look into it.
I note that even with -t latex we get an over-wide table.

Here's the tex produced for the first table:

\begin{longtable}[]{@{}
  >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.1944}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.1111}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.1528}}@{}}
\toprule\noalign{}
\multicolumn{2}{@{}l}{%
\begin{minipage}[b]{\linewidth}\raggedright
Property
\end{minipage}} & \begin{minipage}[b]{\linewidth}\raggedright
Earth
\end{minipage} \\
\midrule\noalign{}
\endhead
\multirow{3}{*}{Temperature 1961-1990} & min & -89.2 °C \\
& mean & 14 °C \\
& min & 56.7 °C \\
\bottomrule\noalign{}
\end{longtable}

@jgm
Copy link
Owner

jgm commented Oct 17, 2023

Output with -t latex:

Screenshot 2023-10-17 at 1 01 31 PM

Here the width is okay on the first table but there is overlap; the second table is too wide.

@jgm
Copy link
Owner

jgm commented Oct 17, 2023

I think we need to pass a parameter for cell width to \multicolumn; looks like it's taking the whole table width.

@jgm
Copy link
Owner

jgm commented Oct 18, 2023

With these tables we get proper widths. The change is that a real width is computed for each \multicolumn, based on the columns containing it.

\begin{longtable}[]{@{}
  >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.1944}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.1111}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.1528}}@{}}
\toprule\noalign{}
\multicolumn{2}{@{}p{(\columnwidth - 4\tabcolsep) * \real{0.21}}}{%
\begin{minipage}[b]{\linewidth}\raggedright
Property
\end{minipage}} & \begin{minipage}[b]{\linewidth}\raggedright
Earth
\end{minipage} \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
\multirow{3}{*}{Temperature 1961-1990} & min & -89.2 °C \\
& mean & 14 °C \\
& min & 56.7 °C \\
\end{longtable}


\begin{longtable}[]{@{}
  >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.3056}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1111}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1111}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1111}}@{}}
\toprule\noalign{}
\multirow{2}{*}{\begin{minipage}[b]{\linewidth}\raggedright
Location
\end{minipage}} & \multicolumn{3}{p{(\columnwidth - 6\tabcolsep) * \real{0.5278}}@{}}{%
\begin{minipage}[b]{\linewidth}\raggedright
Temperature 1961-1990 in degree Celsius
\end{minipage}} \\
& \begin{minipage}[b]{\linewidth}\raggedright
min
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
mean
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
max
\end{minipage} \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
Antarctica & -89.2 & N/A & 19.8 \\
Earth & -89.2 & 14 & 56.7 \\
\end{longtable}

In the first case there is still overlap, but that could at least be fixed by making the cell bigger in the source.
Screen Shot 2023-10-17 at 7 30 17 PM

jgm added a commit that referenced this issue Oct 18, 2023
This should help fix a problem wherein some grid tables with
colspans were overly wide.  See #9140.

The example given there still produces suboptimal
output (overlapping text), so not closing yet.
@jgm
Copy link
Owner

jgm commented Oct 18, 2023

to fix the remaining (overlap) issue, we need to add an explicit width to the \multirow (instead of * = "use natural width").

@jgm jgm closed this as completed in 992bc86 Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants