# Allowing for tables that allow page breaks as well as don't

I have a setup in my preamble that allows this:

\documentclass[12pt]{report}% Not sure what this is for
\usepackage{array,ltablex, makecell}%
\newenvironment{conditions}
{\par\vspace{\abovedisplayskip}\noindent\begin{tabular}{>{$}l<{$} @{${}={}$} l}}
{\end{tabular}\par\vspace{\belowdisplayskip}}%This is for descriptions of equations
\usepackage[]{multirow}%Essential for cells in table spanning multiple rows
\usepackage{tabulary}% This is for tables
\usepackage{longtable,array,ragged2e}% This is formatting for long tables
\usepackage{tabularx,caption}
\newcolumntype{LL}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}%This is a wrapper to make everything a certain width -left aligned columns with stuff at the top.
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}X}%This is a wrapper to make everything a certain width -left aligned columns with stuff at the top.
\newcolumntype{CC}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}%C is for central aligned columns and middle aligned.
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}X}%C is for central aligned columns and middle aligned.
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}

\begin{longtable}{@{}LL{6cm}LL{8cm}@{}}
\caption{Claims that are Difficult to Check}
\label{table:claimimpossible}\\
\toprule
\textbf{Example Sentence} & \textbf{Explanation}\\
\midrule
\bottomrule
\endlastfoot
Long text...... & Long text......\\
\midrule
Long text...... & Long text......\\
\midrule
Long text...... & Long text......\\
\end{longtable}

\begin{table}[!htbp]
\setlength\extrarowheight{3pt}
\setlength\tabcolsep{4pt} % default value: 6pt
\catcode_=13 % Make _ "active";
%% This setting expires at end of current group, i.e., at end of "table" environment
\def_{\textunderscore\hspace{0pt}} % "meaning" of "_"
\caption{List of Open and Closed Evaluation Properties}
\label{table:openclosed}
\ra{1.0}%This stretches the contents of cells
\begin{tabularx}{\textwidth}{|C|C|C|}
\hline
\textbf{Open Properties} & \textbf{Closed Properties} &
\textbf{Sentence Label Properties} \\
\hline
\begin{tabular}{@{}L@{}}
foreign_direct_investment_net_inflows\\
\end{tabular}
&
\begin{tabular}{@{}L@{}}
foreign_direct_investment_net_inflows\\
\end{tabular}
&
\begin{tabular}{@{}L@{}}
foreign_direct_investment_net_inflows\\
\end{tabular}\\
\hline
\end{tabularx}
\end{table}

\end{document}


The first table needs to have page breaks, and fixed column widths, hence I used a longtable. The second type of table needs to be flexible and have the option within its set up to wrap text based on characters such as _, as the word time_required_to_start_a_business will currently never wrap in a cell. However, it doesn't need to allow page breaks.

Currently I am getting an error on my longtable which is:

Package array Error:  Illegal pream-token (4cm)
: c' used.

See the array package documentation for explanation.
Type  H <return>  for immediate help.
...

l.23 ...in{longtable}{@{}LL{4cm}LL{4cm}LL{6cm}@{}}


Note, the second table came from this previous answer, which explains my use case for the underscore based text wrapping I want to achieve (note, preferably not for every table if possible):

Wrapping text in tables which contains underscores

The error is about the array package - I know I am loading this twice but is the error really about that?

• you can't have columntypes named LL and L. Change LL into Y or something. Same with CC, change into B or whatever. – Runar Sep 3 '16 at 15:55
• As @RunarTrollet has noted, the column type names LL and CC are illegal; consider using K and B instead. Moreover, the definitions of the L and C column types are seriously flawed: It makes no sense to assign a variable parameter to them but then not use it -- as, sure enough, is done later on in the body of the document. Separately, it's very bad practice to re-use the column name types C, L and R since these are already defined by the tabulary package, which is loaded by the code. However, do you even need the tabulary package? – Mico Sep 3 '16 at 16:16
• I never need the tabulary package as I never have a tabulary table. What does {>{\centering\let\newline\\\arraybackslash\hspace{0pt}}X} do? Is this a definition purely for the tabularX package, which thus doesn't allow variable parameters? I didn't use a variable parameter as the previous answer for the underscore table did not have such a variable parameter for the C type? – Dhruv Ghulati Sep 3 '16 at 16:30
• Yes, it is for tabularx environments only. But, no, you can use column types with variables in such tables. And, yes, the error is related to the array package and, yes, you should look at its documentation as it will explain much of what is wrong and several of the comments made so far ;). – cfr Sep 4 '16 at 1:33
• \toprule will probably give you an error, although I realise LaTeX is not getting that far at the moment. (Are the claims impossible? Or just difficult to check? Or impossible to check? If they are impossible, why would they need to be checked?) – cfr Sep 4 '16 at 1:36

This needs some further tweaking e.g. to ensure consistent spacing between captions and tables and possibly to reduce the horizontal rules or trim them. However, it does compile and it ensures greater consistency than did the original code.

However, if you do not know what \documentclass[12pt]{report} does, then you need to read an introduction to LaTeX else nothing is going to make much sense.

If you think you don't have time or that it will be easier to just look at examples, you need to rethink.

It will save you time. Massively.

And it will enable you to make sense of the examples rather than randomly copy-pasting bits of code, altering it according to some hypothesis or impulse and then hoping it will somehow work anyway.

If you are lucky, it will fail with errors.

If you are unlucky, it will compile with passable output and you will only discover the mischief much later.

\documentclass[12pt]{report}% Not sure what this is for - ??? this is the class you are using and the default font size
\usepackage{array,booktabs}% you need booktabs, but you're not using makecell
\usepackage{tabularx}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash\hspace{0pt}}p{#1}}%This is a wrapper to make everything a certain width -left aligned columns with stuff at the top.
\newcolumntype{Y}{>{\raggedright\arraybackslash\hspace{0pt}}X}
\newcolumntype{C}[1]{>{\centering\arraybackslash\hspace{0pt}}m{#1}}%C is for central aligned columns and middle aligned.
\newcolumntype{Z}{>{\centering\arraybackslash\hspace{0pt}}X}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash\hspace{0pt}}m{#1}}
\begin{document}
\begin{longtable}{@{}L{6cm}L{8cm}@{}}
\caption{Claims that are Difficult to Check}
\label{table:claimimpossible}\\
\toprule
\textbf{Example Sentence} & \textbf{Explanation}\\
\midrule
\bottomrule
\endlastfoot
Long text...... & Long text......\\
\midrule
Long text...... & Long text......\\
\midrule
Long text...... & Long text......\\
\end{longtable}

\begin{table}[!htbp]
\setlength\extrarowheight{3pt}
\setlength\tabcolsep{4pt} % default value: 6pt
\catcode_=13 % Make _ "active";
%% This setting expires at end of current group, i.e., at end of "table" environment
\def_{\textunderscore\hspace{0pt}} % "meaning" of "_"
\caption{List of Open and Closed Evaluation Properties}
\label{table:openclosed}
\ra{1.0}%This stretches the contents of cells
\begin{tabularx}{\textwidth}{ZZZ}
\toprule
\textbf{Open Properties} & \textbf{Closed Properties} &
\textbf{Sentence Label Properties} \\
\midrule
\begin{tabular}{@{}Y@{}}
foreign_direct_investment_net_inflows\\
\end{tabular}
&
\begin{tabular}{@{}Y@{}}
foreign_direct_investment_net_inflows\\
\end{tabular}
&
\begin{tabular}{@{}Y@{}}
foreign_direct_investment_net_inflows\\
\end{tabular}\\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
`