Generate professional PDFs from Markdown using Pandoc with sophisticated LaTeX table spacing control to prevent awkward page breaks...
This skill provides techniques for generating professional PDFs from Markdown using Pandoc with XeLaTeX, focusing on sophisticated LaTeX table spacing control to prevent awkward page breaks while maintaining readability.
Use this skill when:
Build PDFs from Markdown using Pandoc with XeLaTeX and custom LaTeX preamble:
pandoc document.md \
-o document.pdf \
--pdf-engine=xelatex \
-V mainfont="DejaVu Sans" \
-V geometry:margin=1in \
-H table-spacing.tex
Key parameters:
--pdf-engine=xelatex: Modern LaTeX engine with better font support-H table-spacing.tex: Include custom LaTeX preamble for table formatting-V geometry:margin=1in: Set page marginsDefault behavior: Pandoc converts Markdown tables → LaTeX longtable package
longtable characteristics:
Alternative: tabular package prevents all breaks but requires custom Pandoc Lua filters (complex)
Pragmatic approach: Improve longtable page break behavior through spacing parameters
Create a table-spacing.tex LaTeX preamble file to control table appearance. See assets/table-spacing-template.tex for a starting template.
Key parameters (see references/latex-parameters.md for detailed explanations):
\renewcommand{\arraystretch}{1.0}
\setlength{\extrarowheight}{2pt}
\setlength{\tabcolsep}{6pt}
\usepackage{needspace}
\LTchunksize=100
\widowpenalty=10000
\clubpenalty=10000
needspace: Ensures minimum space before starting table (prevents orphans at bottom)LTchunksize=100: Processes more rows before considering page break (default ~20)widowpenalty/clubpenalty: Discourages single lines at top/bottom of pagesPhase 1: Start with moderate spacing (balance readability and compactness)
\renewcommand{\arraystretch}{1.2}
\setlength{\extrarowheight}{4pt}
\setlength{\tabcolsep}{10pt}
Phase 2: If tables still break awkwardly, tighten spacing
\renewcommand{\arraystretch}{1.0}
\setlength{\extrarowheight}{2pt}
\setlength{\tabcolsep}{6pt}
Phase 3: If still breaking, consider additional measures
\footnotesize or \small before longtableAfter each spacing adjustment:
Regenerate PDF:
pandoc document.md -o document.pdf --pdf-engine=xelatex -H table-spacing.tex
Check table placement: Look for tables breaking across pages
Measure impact: Compare page count, readability, table density
Iterate: Adjust parameters based on results
Important: Always test with actual content - table breaking depends on:
Looser spacing (arraystretch 1.2+, extrarowheight 4pt+, tabcolsep 10pt+):
Tighter spacing (arraystretch 1.0, extrarowheight 2pt, tabcolsep 6pt):
Reality: Some tables are legitimately too tall for one page
Signs:
Options:
\usepackage{pdflscape} for wide tablesComprehensive reference for all LaTeX table spacing parameters, including:
Ready-to-use LaTeX preamble templates:
"Key Findings" table breaking across pages with awkward single-row orphan at bottom.
Attempt 1: Add page break penalties
\usepackage{needspace}
\LTchunksize=100
\widowpenalty=10000
\clubpenalty=10000
Result: Improved placement but table still breaks (didn't reduce table height)
Attempt 2: Reduce spacing to make table physically smaller
\renewcommand{\arraystretch}{1.0} % Was 1.2
\setlength{\extrarowheight}{2pt} % Was 4pt
\setlength{\tabcolsep}{6pt} % Was 10pt
Result: ~20-25% reduction in table height → table fits on single page
The problem wasn't longtable's breaking behavior - the table was physically too tall. Penalties and needspace can't change table height, only placement decisions. Making the table more compact through spacing reduction solved the root cause.