#StackBounty: #tables #longtable #page-breaking #pandoc #markdown Tables converted from markdown to pdf via pandoc puts an unnecessary …

Bounty: 50

I have a project that converts Markdown files into PDF, using pandoc and a LaTeX PDF template.

I’m having a strange issue with the tables. For very few cases (something like 2 in 200 documents), the table is getting inserted after a page break. I’m not sure if it’s a page break or not since I basically have very few experience in LaTeX, but it seems like that.

This is one of the Markdown files that I’m converting:

... More stuff above

Lorem

- Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.

# LOREM IPSUM

## Lorem Ipsum is simply dummy 

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting.

| Column 1                                       | Column 2                                                                    |
| ---------------------------------------------- | --------------------------------------------------------------------------- |
| Lorem Ipsum is simply dummy text               | Lorem Ipsum                                                                 |
| Lorem Ipsum is simply dummy text of the        | Lorem Ipsum is simply dummy text of the printing and typesetting industry.  |

## Lorem Ipsum is simply dummy text of the

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

... More stuff below

My pandoc command is something like this (it gets executed with Powershell, that’s what the variables with dollar signs are about):

pandoc  --metadata=title:"asasas" `
        --resource-path="$markdownPath" `
        --template="$pdfTemplatePath" `
        --fail-if-warnings `
        --variable numbersections="true" `
        --variable mainfont="Arial" `
        --variable sansfont="Helvetica" `
        --variable monofont="Courier" `
        --variable fontsize=12pt `
        --variable version=2.0 `
        --variable geometry="left=20mm, top=10mm, right=20mm, bottom=20mm" `
        --variable toc-own-page="true" `
        --toc `
        --toc-depth=5 `
        --lua-filter="version_table.lua" `
        --variable titlepage="true" `
        --variable logo="PDF/logo.eps" `
        --columns=50 `
        -f markdown-implicit_figures+escaped_line_breaks+raw_tex `
        -t latex `
        -s `
        -o "$outputFileName" `
        "$tempFileName"

The PDF template I’m using is very similar to pandoc-latex-template, probably built on top of it.

When I run pandoc command, this is what the output looks like for the table:

enter image description here

Any idea what the problem could be? Anything I should try, that could help?

This is the part of the generated tex file for the screenshot above

PassOptionsToPackage{unicode}{hyperref}
PassOptionsToPackage{hyphens}{url}
PassOptionsToPackage{dvipsnames,svgnames*,x11names*,table}{xcolor}
%
documentclass[
  12pt,
  a4paper,
,tablecaptionabove
]{scrartcl}
usepackage{lmodern}
usepackage{setspace}
setstretch{1.2}
usepackage{amssymb,amsmath}
usepackage{ifxetex,ifluatex}
usepackage[utf8x]{inputenc}
ifnum 0ifxetex 1fiifluatex 1fi=0 % if pdftex
  usepackage[T1]{fontenc}
  % usepackage[utf8x]{inputenc}
  usepackage{textcomp} % provide euro and other symbols
else % if luatex or xetex
  usepackage{unicode-math}
  defaultfontfeatures{Scale=MatchLowercase}
  defaultfontfeatures[rmfamily]{Ligatures=TeX,Scale=1}
  setmainfont[]{Arial}
  setsansfont[]{Helvetica}
  setmonofont[]{Courier}
fi
% Use upquote if available, for straight quotes in verbatim environments
IfFileExists{upquote.sty}{usepackage{upquote}}{}
IfFileExists{microtype.sty}{% use microtype if available
  usepackage[]{microtype}
  UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
makeatletter
@ifundefined{KOMAClassName}{% if non-KOMA class
  IfFileExists{parskip.sty}{%
    usepackage{parskip}
  }{% else
    setlength{parindent}{0pt}
    setlength{parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
  KOMAoptions{parskip=half}}
makeatother
usepackage{xcolor}
definecolor{default-linkcolor}{HTML}{A50000}
definecolor{default-filecolor}{HTML}{A50000}
definecolor{default-citecolor}{HTML}{4077C0}
definecolor{default-urlcolor}{HTML}{4077C0}
IfFileExists{xurl.sty}{usepackage{xurl}}{} % add URL line breaks if available
IfFileExists{bookmark.sty}{usepackage{bookmark}}{usepackage{hyperref}}
hypersetup{
  pdftitle={asasas},
  hidelinks,
  breaklinks=true,
  pdfcreator={LaTeX via pandoc with the Eisvogel template}}
urlstyle{same} % disable monospaced font for URLs
usepackage[margin=2.5cm,includehead=true,includefoot=true,centering,left=20mm, top=10mm, right=20mm, bottom=20mm]{geometry}
usepackage[export]{adjustbox}
usepackage{graphicx}
usepackage{longtable,booktabs}
% Correct order of tables after paragraph or subparagraph
usepackage{etoolbox}
makeatletter
patchcmdlongtable{par}{if@noskipsecmbox{}fipar}{}{}
makeatother
% Allow footnotes in longtable head/foot
IfFileExists{footnotehyper.sty}{usepackage{footnotehyper}}{usepackage{footnote}}
makesavenoteenv{longtable}
usepackage{graphicx,grffile}
makeatletter
defScaleWidthIfNeeded{%
 ifdimGin@nat@width>linewidth
    linewidth
  else
    Gin@nat@width
  fi
}
defScaleHeightIfNeeded{%
  ifdimGin@nat@height>0.9textheight
    0.9textheight
  else
    Gin@nat@width
  fi
}
makeatother

setkeys{Gin}{width=ScaleWidthIfNeeded,height=ScaleHeightIfNeeded,keepaspectratio}%
setlength{emergencystretch}{3em}  % prevent overfull lines
providecommand{tightlist}{%
  setlength{itemsep}{0pt}setlength{parskip}{0pt}}
setcounter{secnumdepth}{5}

usepackage{float}
floatplacement{figure}{H}


title{asasas}
date{}


ifnum 0ifxetex 1fiifluatex 1fi=0 % if pdftex
  usepackage[shorthands=off,main=english]{babel}
else
  usepackage{polyglossia}
  setmainlanguage[]{english}
fi

usepackage{pagecolor}
usepackage{afterpage}

usepackage{multicol}

PassOptionsToPackage{hyphens}{url}

usepackage{csquotes}

definecolor{caption-color}{HTML}{777777}
usepackage[font={stretch=1.2}, textfont={color=caption-color}, position=top, skip=4mm, labelfont=bf, singlelinecheck=false, justification=raggedright]{caption}
setcapindent{0em}

definecolor{blockquote-border}{RGB}{221,221,221}
definecolor{blockquote-text}{RGB}{119,119,119}
usepackage{mdframed}
newmdenv[rightline=false,bottomline=false,topline=false,linewidth=3pt,linecolor=blockquote-border,skipabove=parskip]{customblockquote}
renewenvironment{quote}{begin{customblockquote}list{}{rightmargin=0emleftmargin=0em}%
itemrelaxcolor{blockquote-text}ignorespaces}{unskipunskipendlistend{customblockquote}}

definecolor{heading-color}{RGB}{40,40,40}
addtokomafont{section}{color{heading-color}}

usepackage{titling}
title{asasas}
author{}

% tables
definecolor{table-row-color}{HTML}{F5F5F5}
definecolor{table-rule-color}{HTML}{999999}

arrayrulecolor{table-rule-color}     % color of toprule, midrule, bottomrule
setlengthheavyrulewidth{0.3ex}      % thickness of toprule, bottomrule
renewcommand{arraystretch}{1.3}     % spacing (padding)

letoldlongtablelongtable
letendoldlongtableendlongtable
renewenvironment{longtable}{
rowcolors{3}{}{table-row-color!100}  % row color
oldlongtable} {
endoldlongtable
globalrownum=0relax}
setlength{parindent}{0pt}
setlength{parskip}{6pt plus 2pt minus 1pt}
setlength{emergencystretch}{3em}  % prevent overfull lines

usepackage{fancyhdr,lastpage}

fancypagestyle{eisvogel-header-footer}{
  fancyhead{}
  fancyfoot{}
  lhead[]{asasas}
  chead[]{}
  rhead[asasas]{}
  lfoot{{Version: 2}{, effective date: 01-Sep-2020}}
  cfoot[]{}
  rfoot{{thepage} of pageref{LastPage}}
  renewcommand{headrulewidth}{0.4pt}
  renewcommand{footrulewidth}{0.4pt}
}
pagestyle{eisvogel-header-footer}

ifxparagraphundefinedelse
  letoldparagraphparagraph
  renewcommand{paragraph}[1]{oldparagraph{#1}mbox{}}
fi
ifxsubparagraphundefinedelse
  letoldsubparagraphsubparagraph
  renewcommand{subparagraph}[1]{oldsubparagraph{#1}mbox{}}
fi

usepackage[table]{xcolor}
usepackage{tabularx}
usepackage{colortbl}


begin{document}

arrayrulecolor{table-rule-color}
restoregeometry

{
setcounter{tocdepth}{5}
tableofcontents
newpage
}

hypertarget{process-description}{%
section{LOREM IPSUM}label{process-description}}

Lorem Ipsum is simply dummy text of the printing
and typesetting industry. Lorem Ipsum has been the
industry's standard dummy text ever since the
1500s, when an unknown printer took a galley of
type and scrambled it to make a type specimen
book. It has survived not only five centuries, but
also the leap into electronic typesetting.

hypertarget{objective-and-benefits}{%
section{OBJECTIVE AND
BENEFITS}label{objective-and-benefits}}

hypertarget{objective}{%
subsection{Objective}label{objective}}

Lorem Ipsum is simply dummy text of the printing
and typesetting industry. Lorem Ipsum has been the
industry's standard

hypertarget{benefits}{%
subsection{Benefits}label{benefits}}

begin{itemize}
item
   Lorem Ipsum is simply dummy text of the printing
and typesetting industry.
item
  Lorem Ipsum is simply dummy text of the printing
and typesetting industry.
end{itemize}

hypertarget{definition}{%
section{DEFINITION}label{definition}}

Lorem Ipsum

begin{itemize}
tightlist
item
   Lorem Ipsum is simply dummy text of the printing
and typesetting industry.
end{itemize}

Lorem Ipsum

begin{itemize}
tightlist
item
  Lorem Ipsum is simply dummy text of the printing
and typesetting industry. Lorem Ipsum has been the
industry's standard dummy text ever since the
1500s, when an unknown printer took
end{itemize}

Lorem Ipsum

begin{itemize}
tightlist
item
  Lorem Ipsum is simply dummy text of the printing
and typesetting industry. Lorem Ipsum has been the
industry's standard dummy 
end{itemize}

Lorem Ipsum

begin{itemize}
tightlist
item
Lorem Ipsum is simply dummy text of the printing
and typesetting industry. Lorem Ipsum has been the
industry's standard dummy text
end{itemize}

Lorem

begin{itemize}
tightlist
item
  Lorem Ipsum is simply dummy text of the printing
  and typesetting industry. Lorem Ipsum is 
end{itemize}

Lorem

begin{itemize}
tightlist
item
  Lorem Ipsum is simply dummy text of the printing
  and typesetting industry. Lorem Ipsum is 
end{itemize}

hypertarget{roles-responsibilities}{%
section{LOREM IPSUM}label{roles-responsibilities}}

Lorem

begin{itemize}
tightlist
item
  Lorem Ipsum is simply dummy text of the printing
  and typesetting industry. Lorem Ipsum has been
  the industry's standard dummy text ever since
  the 1500s Lorem Ipsum is simply dummy text of the printing
  and typesetting industry. Lorem Ipsum has been
  the industry's standard dummy text ever since
  the 1500s.
end{itemize}

Lorem

begin{itemize}
tightlist
item
  Lorem Ipsum is simply dummy text of the printing
  and typesetting industry. Lore
end{itemize}

Lorem

begin{itemize}
tightlist
item
  Lorem Ipsum is simply dummy text of the printing
  and typesetting industry.
end{itemize}

Lorem

begin{itemize}
tightlist
item
  Lorem Ipsum is simply dummy text of the printing
  and typesetting industry. Lorem Ipsum has been
  the industry's standard dummy text ever since
  the 1500s.
end{itemize}

Lorem

begin{itemize}
tightlist
item
  Lorem Ipsum is simply dummy text of the printing
  and typesetting industry. Lorem Ipsum has been
  the industry's standard dummy text ever since
  the 1500s.
end{itemize}

hypertarget{lorem-ipsum}{%
section{LOREM IPSUM}label{lorem-ipsum}}

hypertarget{lorem-ipsum-is-simply-dummy}{%
subsection{Lorem Ipsum is simply
dummy}label{lorem-ipsum-is-simply-dummy}}

Lorem Ipsum is simply dummy text of the printing
and typesetting industry. Lorem Ipsum has been the
industry's standard dummy text ever since the
1500s, when an unknown printer took a galley of
type and scrambled it to make a type specimen
book. It has survived not only five centuries, but
also the leap into electronic typesetting.

begin{longtable}[]{@{}ll@{}}
toprule
begin{minipage}[b]{0.36columnwidth}raggedright
Column 1strut
end{minipage} &
begin{minipage}[b]{0.58columnwidth}raggedright
Column 2strut
end{minipage}tabularnewline
midrule
endhead
begin{minipage}[t]{0.36columnwidth}raggedright
Lorem Ipsum is simply dummy textstrut
end{minipage} &
begin{minipage}[t]{0.58columnwidth}raggedright
Lorem Ipsumstrut
end{minipage}tabularnewline
begin{minipage}[t]{0.36columnwidth}raggedright
Lorem Ipsum is simply dummy text of thestrut
end{minipage} &
begin{minipage}[t]{0.58columnwidth}raggedright
Lorem Ipsum is simply dummy text of the printing
and typesetting industry.strut
end{minipage}tabularnewline
bottomrule
end{longtable}
    
end{document}


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.