I am facing a situation where I am somewhat faced with the modular and conditional assembly of a table which prevents the \begin{} and \end{} definitions from remaining in the same local context. Confusing yes, (see code at end of question), but I don't think this part is all that critical. It is merely the nature of the restriction, which produces the problem that has been described elsewhere, namely: Too long vertical lines in table
This question provides excellent screen shots that describes the problem (i.e. vertical lines of a table extending past the last row) although my table doesn't look much like it or those produced in the accepted answer.
My MWE is here:
\documentclass{article}
\usepackage{xparse}
\usepackage{environ,longtable,threeparttablex,booktabs,multirow,array,adjustbox,supertabular}% table adjustment packages
% change spacing/padding of long table: https://tex.stackexchange.com/questions/5683/how-to-remove-top-and-bottom-whitespace-of-longtable
\setlength{\LTpre}{0pt}
\setlength{\LTpost}{0pt}
% Wrapping text in multicolumn: https://tex.stackexchange.com/questions/115668/wrapping-text-in-multicolumn
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
%https://tex.stackexchange.com/questions/70919/vertical-aligning-in-longtable-environment
%\adjustbox{valign=t}{}
%\raisebox{\normalbaselineskip-\height}{#6} & \multicolumn{2}{L{11cm}}{#7}
% changed m to p instead
\makeatletter
\newcommand\eatpar{\@ifnextchar\par{\expandafter\eatpar\@gobble}\relax}
\makeatother
%--------------------New Commands for consistent formatting ---------------
\ExplSyntaxOn
% this one can't be a held in a local variable because the table paramaters are external
\DeclareDocumentCommand{\TableAssembly}{ m m }{%
#1 & #2 \\%
}%
\NewDocumentCommand{\BuildTablePortion}{ O{R{2.5cm} | L{12.25cm}} m }%
{%
\seaton_BuildTablePortion:nn { #1 }{ #2 }%
}%
\cs_new:Npn \seaton_BuildTablePortion:nn #1 #2 %
{%
\str_case:nnF { #2 }{%
{START}{%
\begin{ThreePartTable}%
\begin{TableNotes}[para,flushleft]%
\end{TableNotes}%
\renewcommand\multirowsetup{\raggedleft}%
\begin{longtable}[l]{#1}%
}%
{END}{%
\eatpar%
%\\\insertTableNotes%
\let\\=\relax%
\end{longtable}%
\end{ThreePartTable}%
}%
% other possible strings
}{ Failed to recognize instruction string #2}%
}%
\ExplSyntaxOff
\begin{document}
\BuildTablePortion{START}
\TableAssembly{1}{2}
\TableAssembly{1}{3}
\BuildTablePortion{END}
\end{document}
There is a comment in response to this answer here: https://tex.stackexchange.com/a/61879/69378 that I would like to understand a bit more about in order to properly address the issue.
When you have a newline after \hline and before \end{tabular} TeX assumes you want to add a new row to the table, but upon detecting no data, ends the table. Just remove the newline and you should be set.
Pretty self explanatory, but because the code I am being given to work with is using macros to create the table, fill the table, and close the table, I cannot use this work around of placing all declarations on the same line.
i.e.
\hline \end{longtable} \end{ThreePartTable}%
instead of
\hline%
\end{longtable}%
\end{ThreePartTable}%
I did some reading and to the best of my applications I thought \let\\=\relax%
or a new command like \newcommand\eatpar{\@ifnextchar\par{\expandafter\eatpar\@gobble}\relax}
might help.
I tried placing them in virtually every permutation relative to the table close block and even in the table population command so I am quite sure there is something that supersedes these manipulations of the relax
command that I am unaware of...
The linked question/answer/comments are a few years old, is the table environment really (or still) this sensitive to new lines?
\obeylines
or\verbatim
or similar constructs are in force)\par
(for two) never as a newline. As always, your question would be much easier to answer if you provided a complete small document that demonstrated the problem. the "workarounds" that you mention of having or not having line ends will make no difference so it is hard to guess what problem this is asking about, with no example provided.%
at ends of lines are needed. presumably if you are getting a spurious cell on the last row causing vertical lines then\insertTableNotes
is generating that, but you don't show its definition.\\\insertTableNotes
but the problem persists (as chosen to present in my MWE. Also, the extra `\` before the call seems necessary or I get an align error...