I initially had a tabularx
setup that was working well, and this included 3 tabular
tables, each representing a single long column.
However, now the table is long and has to span multiple pages, so I need a longtable
. For the sake of length I do not want to provide the tabularx
setup that worked.
Here is my code:
\documentclass[12pt]{report}
\usepackage{array,ltablex,makecell}% ltablex loads tabularx and longtable also
\renewcommand\theadfont{\normalsize\bfseries}
% \renewcommand*\descriptionlabel[1]{\hspace\leftmargin$#1$}%This is for descriptions to appear on the LHS with an indent
\usepackage[]{multirow}%Essential for cells in table spanning multiple rows
\usepackage[autostyle]{csquotes}% This is for quotes
% \usepackage{tabulary}% This is for tables
\usepackage{ragged2e}% This is formatting for long tables
\usepackage[font={small}]{caption}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}%This is a wrapper to make everything a certain width -left aligned columns with stuff at the top.
\newcolumntype{U}{>{\raggedright\arraybackslash\hspace{0pt}}X}%This is a wrapper to make everything a certain width -left aligned columns with stuff at the top.
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}%C is for central aligned columns and middle aligned, p puts stuff at the bottom, m middles everything.
\newcolumntype{Y}{>{\centering\arraybackslash\hspace{0pt}}X}%C is for central aligned columns and middle aligned.
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
% \newcommand{\specialcell}[2][c]{\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}%This is to force new lines in cells
\usepackage{hhline}%
\usepackage[table, svgnames]{xcolor}%
\usepackage{graphicx}% This is for images
\usepackage{booktabs,dcolumn,caption}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}%This is for precision tables per property
% \captionsetup{labelsep=newline,singlelinecheck=false} % optional, this makes the caption numbers appear on a new line.
\begin{document}
\begin{longtable}{C{4cm}C{4cm}C{4cm}}
\caption{List of Open and Closed Evaluation Properties}
\label{table:openclosed}
\scriptsize
% \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 "_"
\ra{1.0}\\
\toprule
\textbf{Open Properties} & \textbf{Closed Properties} &
\textbf{Sentence Label Properties} \\
\midrule
\multicolumn{1}{C{4cm}}{consumer_price_index
cpi_inflation_rate
diesel_price_liter
fertility_rate
foreign_direct_investment_net_inflows
gdp_growth_rate
gdp_nominal
gdp_nominal_per_capita
gdp_real
gni_in_ppp_dollars
gni_per_capita_in_ppp_dollars
health_expenditure_as_percent_of_gdp
internet_users_percent_population
labor_participation_rate
life_expectancy
merchandise_trade_percent_of_gdp
net_migration
population
population_growth_rate
prevalence_of_undernourisment
renewable_freshwater_per_capita
size_of_armed_forces
time_required_to_start_a_business
trade_balance_as_percent_of_gdp
}
&
\multicolumn{1}{C{4cm}}{consumer_price_index
cpi_inflation_rate
diesel_price_liter
fertility_rate
gdp_nominal
gdp_nominal_per_capita
gni_in_ppp_dollars
gni_per_capita_in_ppp_dollars
health_expenditure_as_percent_of_gdp
internet_users_percent_population
labor_participation_rate
life_expectancy
population
population_growth_rate
prevalence_of_undernourisment
renewable_freshwater_per_capita
}
&
\multicolumn{1}{C{4cm}}{
agriculture_as_percent_of_gdp
arithmetic_population_density
automobiles_per_capita
brain_drain_percent
broadband_penetration_rate
child_labor_percent
co2_emissions_commercial
co2_emissions_industrial
co2_emissions_mobile
co2_emissions_per_capita
co2_emissions_residential
co2_emissions_total
consumer_price_index
cpi_inflation_rate
debt_service_as_percent_of_trade_volume
deposit_interest_rate
diesel_price_liter
electricity_consumption_per_capita
electricity_production
energy_use_per_capita
exports_as_percent_of_gdp
external_debt_stock
fertility_rate
foreign_direct_investment_net_inflows
gas_price_liter
gdp_deflator_change
gdp_growth_rate
gdp_nominal
gdp_nominal_per_capita
gdp_real
global_competitiveness_index
gni_in_ppp_dollars
gni_per_capita_in_ppp_dollars
government_debt_percent_gdp
greenhouse_gas_emission
greenhouse_gas_emission_intensity
greenhouse_gas_emissions_per_capita
gross_capital_formation_as_percent_of_gdp
gross_savings_as_percent_of_gdp
health_expenditure_as_percent_of_gdp
high_tech_as_percent_of_manufactured_exports
hiv_prevalence_rate
household_consumption_expenditure_as_percent_of_gdp
imports_as_percent_of_gdp
industry_as_percent_of_gdp
internet_users
internet_users_percent_population
labor_participation_rate
lending_interest_rate
life_expectancy
literacy_rate
long_term_unemployment_rate
market_cap_of_listed_companies_as_percent_of_gdp
merchandise_trade_percent_of_gdp
military_expenditure_percent_gdp
minimum_wage
natural_gas_production
net_migration
net_workers_remittances
official_development_assistance
oil_production
part_time_employment_percent
population
population_growth_rate
poverty_rate_2dollars_per_day
prevalence_of_undernourisment
renewable_freshwater_per_capita
services_as_percent_of_gdp
size_of_armed_forces
smoking_prevalence_rate
tax_revenue_percent_of_gdp
time_required_to_start_a_business
trade_balance_as_percent_of_gdp
unemployment_rate
}
\\\bottomrule
\end{longtable}\label{listofproperties}
\end{document}
I am currently getting:
Missing $ inserted.
<inserted text>
$
l.279 }
At the end of the first multicolumn
. What am I doing wrong here? I tried multirow
with a fixed 4cm gap and 25 rows but still had the same error.
The original table with tabularx
looked like:
Best Answer
Problematic table
The error occurs because the
\catcode`_=13
is set within thelongtable
, so that it's scope would be only effective for a single row. I've moved this code outside thelongtable
and added curly braces around it, and thelongtable
to limit the scope of this.When you use
\multicolumn
and set add lots of text inside, the content will be treated as a single cell, solongtable
is not able to the content, as it cannot break a cell, only rows.Further suggestions
\endhead
and friends fromlongtable
-package to have the same headers and footers on every page.consumer_price_index
, set them in monospace font, using\ttfamily
or\texttt
._
possible with theunderscore
-package. There are multiple alternatives.\let\newline\\\arraybackslash
. Who gave you that code?tabulary
is meant for tables, yes, but what does it actually do? You don't need it for tables, and the comment would just confuse you, and everybody reading your code.Output
Here is a comparison of 3,4 and 5-columns for your content. it can easilty be changed with changin
before=\begin{multicols}{3}
Code
Alternate approach
As I interpret, you simply want a list of some variables, or properties. Therefore, a list would be more suited, than a tabular, which is more intented to compare and differentiate information, not list them. Therefore I suggest a modified
itemize
-environment calledpropertyList
. It should be highly modifieable. You can easaly adjust how many columns you want, spacing, font and such, with theenumitem
-package.Output
Code