# Hide or show complete rows of longtabu or longtable LaTeX table

I would like to toggle on/off complete rows of a longtabu or longtable table. The following post:

hide/show complete row of tabular

provides elegant working solutions (which I presume are roughly identical) for a tabular environment table.

Unfortunately, when used with a longtabu or longtable table or, indeed, even just the tabu table environment, I get the following error:

ERROR: Paragraph ended before \rowswitch was complete.

--- TeX said ---
\par
l.208   \end{longtabu}

--- HELP ---
A blank line occurred in a command argument that shouldn't contain
one. You probably forgot the right brace at the end of an argument.


My table is very long, so I would seem to need to use either the longtabu or longtable environments.

I'm using the memoir class, but I seem to get the same error with the article class.

The following is a MWE (using the Carlisle solution) that does not work in just the above way.

\documentclass[a4paper,landscape,10pt,oneside,english]{memoir}
% memoir set margins
\setlrmarginsandblock{1.5cm}{1.5cm}{*}      % left-right
\setulmarginsandblock{2.5cm}{1.5cm}{*}      % upper-lower
\checkandfixthelayout

\usepackage{comment}
\usepackage{lipsum}
\usepackage{longtable,tabu}
\usepackage{rotating}
\usepackage{blindtext}

%%  toggle switches to hide/unhide rows of table:
%  \def\rowswitch#1\\{#1\\} %On = Unhide
\def\rowswitch#1\\{} %Off = Hide

\begin{document}
\begin{longtabu} to\textwidth{
| X[2,l]
| X[2,l]
| X[15,l]
| X[15,l]
| X[2,l]
| }
\hline \hline
\textbf{Ref} &
\textbf{Ref} &
\textbf{Summary} &
\textbf{Summary} &
\textbf{Ref}
\\ \hline \hline \hline \hline
&
&
\blindtext
&
&
\\ \hline
\rowswitch
&
Hidden row
&
Hidden row
\blindtext
&
Hidden row
&
\\ \hline
&
&
\blindtext
&
&
\\ \hline
\end{longtabu}
\end{document}


For longtable, one can substitute:

\begin{longtable}{
| p{1cm}
| p{1cm}
| p{10cm}
| p{10cm}
| p{1cm}
| }


and

\end{longtable}


to get the same error.

• remove all the blank lines (or define \rowswitch by \long\def) – David Carlisle Oct 27 '18 at 15:47
• Thanks David, \long\def\rowswitch#1\\{} etc works much better and remains very elegant. – Morpheus Oct 27 '18 at 16:51

You should remove all the blank lines (or define \rowswitch by \long\def or \newcommand rather than \def).
Removing the blank lines is perhaps the best solution as blank lines should never be used just for "pretty printing" the source layout in TeX, they are an instruction and reported as \par by TeX's file reading code. A paragraph break is not expected here (which is why the error is raised).
However even if you do remove the blank lines you should still make the command \long so that you can skip over paragraphs in p columns.