4

I run latexmk -pdfxe on this MWE

\documentclass[landscape]{article}
\pagestyle{plain}
\usepackage[hmargin=1cm, vmargin=2cm]{geometry}

\usepackage{longtable}
\usepackage{booktabs}
\usepackage{array}
\usepackage{threeparttable}
\usepackage[referable]{threeparttablex}
\usepackage{arydshln}

\LTpre0pt\LTpost0pt
\LTleft1em\LTright1em
\newlength\tabcolwidth
\newlength\firstcoltext
\newlength\rowheight
\setlength{\footskip}{0pt}
\setlength{\rowheight}{13ex}
\newcolumntype{y}[1]{>{\raggedright\arraybackslash}p{#1}}

\begin{document}
\centering\large
\LTcapwidth=\textwidth
\settowidth\firstcoltext{longest~}
\setlength\tabcolwidth{\dimexpr.5\textwidth-\firstcoltext-\tabcolsep-10pt}
\begin{ThreePartTable}
  % \renewcommand\TPTminimum{\textwidth}
  \begin{TableNotes}
    \item[a] \label{tn:a} foo
    \item[b] \label{tn:b} bar
    % \unskip\strut\par
  \end{TableNotes}
  \begin{longtable}{%
      @{\extracolsep{\fill}}ry{\tabcolwidth}:y{\tabcolwidth}@{}}
      \caption{Please fill in this table.}\\
      \toprule
      \multicolumn{1}{r}{~}
      & \multicolumn{1}{y{\tabcolwidth}}{A}
      & \multicolumn{1}{y{\tabcolwidth}}{B} \\
    \midrule
    \endhead
    \cmidrule{3-3}
    \multicolumn{3}{r}{\raggedleft\textit{continued \ldots}}
    \endfoot
    \bottomrule
    \insertTableNotes\\
    \endlastfoot
    \multicolumn{1}{r:}{foo} & & \\[\rowheight]\cdashline{2-3}
    longest\tnotex{tn:a} & & \\[\rowheight]\cline{1-3}
    foo & & \\[\rowheight]\cdashline{2-3}
    bar\tnotex{tn:b} & & \\[\rowheight]\cdashline{2-3}
    baz & & \\[\rowheight]
  \end{longtable}
\end{ThreePartTable}
\end{document}

results in

enter image description here

How do I get the lines aligned properly? I know this seems similar to this question


edit: Adopting the solution from Herbert's answer, I now excluded booktabs completely. I tried to use \Xhline and \Xcline from the makecell package, the first of which is defined:

\newcommand\Xhline[1]{\noalign{\ifnum0=‘}\fi\arrayrulewidth#1%
\ifx\hline\LT@hline\let\@xhline\LT@@hline\fi
\hrule\@height\arrayrulewidth\futurelet\reserved@a\@xhline}

But the rules appear thicker than expected because apparently there's another \hline included. Try uncommenting the arrayrulewidth line. (Or change to \multicolumn{1}{X@{}}{A} which causes the table to overflow.) The problem of the intersecting vertical dashed line is also similar using \Xhline to booktabs's \midrule (I corrected it from running about 2pt into the head). Finally, I also w'd like the footer to be shown "after" the last row on the page.

\documentclass[landscape,a5paper]{article}
\pagenumbering{gobble}
\pagestyle{plain}
\usepackage[hmargin=1cm, top=2cm, bottom=4cm]{geometry}
\usepackage{array}     % \firsthline \lasthline
\usepackage{makecell}  % \Xhline \Xcline
\usepackage{xltabular}
\usepackage{ragged2e}
\usepackage{arydshln}  % \firsthdashline \lasthdashline
\renewcommand{\arraystretch}{1.5}
\newlength\heavyrulewidth
\newlength\lightrulewidth
\newlength\rowheight
\renewcommand\tabularxcolumn[1]{>{\RaggedRight}p{#1}}
\usepackage{etoolbox}
\AtBeginEnvironment{xltabular}{\hfuzz1pt}
\begin{document}
  \centering\small
  % lengths from booktabs.sty
  \setlength\heavyrulewidth{0.08em}
  \setlength\lightrulewidth{0.05em}
  % \setlength\arrayrulewidth{0pt}   % <-- uncomment
  \setlength\tabcolsep{1em}
  \setlength\rowheight{6ex}
  \LTcapwidth=\textwidth
  \noindent
  \begin{xltabular}{\linewidth}{@{} r X : X @{}}
    \caption{Please fill in this table.}\\\Xhline{\heavyrulewidth}
    % \rule[-1.25ex]{0pt}{4ex}
    & \multicolumn{1}{X}{A}
    & \multicolumn{1}{X}{B}\\[-2pt]\Xhline{\lightrulewidth}
    \endhead
    \Xcline{3-3}{\lightrulewidth}
    \multicolumn{3}{r}{\raggedleft\textit{continued \ldots}}
    \endfoot
    \Xhline{\heavyrulewidth}
    \endlastfoot
    foo & & \\[\rowheight]\cdashline{2-3}
    bar\footnote{bar} & & \\[\rowheight]\cdashline{2-3}
    foo & & \\[\rowheight]\cdashline{2-3}
    test a footnote\footnote{foo} & & \\[\rowheight]\cline{1-3}
    foo & & \\[\rowheight]\cdashline{2-3}
    foo & & \\[\rowheight]\cdashline{2-3}
    foo & & \\[\rowheight]
  \end{xltabular}
\end{document}

This is the first page:

a long table with a few alignment problems

edit: (27/05/2018)

I've created a gist with a table that illustrates the application and the reason for vertical lines. I would like top and bottom \hlines to have different thicknesses though.

3
  • What exactly is the problem?
    – Bernard
    Commented May 17, 2018 at 19:22
  • what do you mean by properly? which lines do you want to change? Commented May 17, 2018 at 19:23
  • I want the vertical dashed rule to start flush with \midrule and at the same time make use of the booktabs features (rulewidth, \belowrulesep, \aboverulesep, etc...). (I had included the first multicolumn with {r:} just to illustrate that the dashed rules do indeed cross \midrule)
    – Bart
    Commented May 18, 2018 at 11:00

1 Answer 1

2

It is a problem with booktabs which inserts some more vertical space before and after the horizontal lines. Use simple \hlines and stretch the first line. I used xltabular which does nearly the same as threeparttable. Important is only:

 \caption{Please fill in this table.}\\\hline
    \rule[-1.25ex]{0pt}{4ex} & A & B \\\hline

Here is my full example:

\documentclass[landscape]{article}
\pagestyle{plain}
\usepackage[hmargin=1cm, vmargin=2cm]{geometry}    
\usepackage{booktabs}
\usepackage{xltabular,ragged2e}
\usepackage{arydshln}

\newlength\rowheight
\setlength{\rowheight}{13ex}
\renewcommand\tabularxcolumn[1]{>{\RaggedRight}p{#1}}

\begin{document}
\centering\large
\LTcapwidth=\textwidth

\noindent
\begin{xltabular}{\linewidth}{@{} r X : X @{}}
\caption{Please fill in this table.}\\\hline
  \rule[-1.25ex]{0pt}{4ex} & A & B \\\hline
\endhead
\cmidrule{3-3}
\multicolumn{3}{r}{\raggedleft\textit{continued \ldots}}
\endfoot
\bottomrule
\endlastfoot
\multicolumn{1}{@{}r:}{foo} & & \\[\rowheight]\cdashline{2-3}
            longest\footnote{foo} & & \\[\rowheight]\cline{1-3}
            foo & & \\[\rowheight]\cdashline{2-3}
            bar\footnote{bar} & & \\[\rowheight]\cdashline{2-3}
            baz & & \\[\rowheight]
\end{xltabular}
\end{document}

enter image description here

1
  • thanks for your almost acceptable solution, please see my edit
    – Bart
    Commented May 18, 2018 at 18:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .