2

I have the following table which I would like to span over 2+ pages. I have tried using longtable, ltxtable, tabu, etc, but must be doing something wrong. It was originally a tabularx table, and I would like to keep the original formatting as much as possible (as other contributors should be adding to the table). How can I get this to span multiple pages with minimal modification to the contents of the table, (i.e. keeping hdashline, multicolumn, etc)? Thanks.

PS - (I would like the caption to be at the bottom of the figure/page as that is how it is in the rest of the document.)

Example

% Example
\documentclass[a4paper, 11pt]{article}

\usepackage{amsmath} % Nice maths symbols.
\usepackage{amssymb} % Nice variable symbols.
\usepackage{array} % Allow for custom column widths in tables.
\usepackage{arydshln} % Dashed lines using \hdashline \cdashline
\usepackage{bbm} % Gives Blackboard fonts.
\usepackage{bm} % Bold math symbols.
\usepackage[margin=10pt,font=small,labelfont=bf,labelsep=endash]{caption} % Caption figures and tables nicely.
\usepackage{enumitem} % Nice listing options in itemize and enumerate.
\usepackage{esdiff} % Gives nice differential operators.
\usepackage{esvect} % Gives nice vector arrows.
\usepackage{float} % Nice figure placement.
\usepackage{geometry} % Use nice margins.
\usepackage{graphicx} % Include figures.
\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue,citecolor=blue,anchorcolor=blue]{hyperref} % Colour links.
\usepackage{indentfirst} % Indents the first paragraph.
\usepackage{letltxmacro} % For defining a nice SQRT symbol.
\usepackage{multirow} % Nice table cells spanning many rows.
\usepackage{multicol} % If I want to use multiple columns.
\usepackage[numbers, sort&compress]{natbib} % Nice references.
\usepackage{physics} % Nice partial derivatives and BRAKET notation.
\usepackage{subcaption} % Side by side figures.
\usepackage{tabularx} % Tables with justified columns.
\usepackage{tikz} % For drawing pictures.

% Gives nice margins.
\geometry{left=20mm, right=20mm, top=20mm, bottom=20mm}

% Removes hyphenation
\tolerance=1
\emergencystretch=\maxdimen
\hyphenpenalty=10000
\hbadness=10000

% Custom column widths using C{2cm}, L, R, etc.
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}


\begin{document}


\begin{table}[hbt]
\begin{center}
\footnotesize
% Try to input a short description (no more than 1 or 2 lines) of algorithms in alphabetical order.
\begin{tabularx}{\textwidth}{|L{0.4\textwidth}|X|}
\hline 
\multicolumn{1}{|c|}{Algorithm}  % use \texttt{text} instead of \verb|text| to allow line breaks for long function names.
& \multicolumn{1}{c|}{Description} \\
\hline 
\texttt{edgeupperbound.m} & Adds the cheapest unused edge that won't create a fork or a loop until a path is formed, then adds in the final edge to create a loop. \\
\hdashline
\texttt{FD\_bruteForce.m} & Explores all possible paths recursively tracking the total distance of smaller networks. \\
\hdashline
\texttt{FD\_dynamicProgramming.m} & Explores all possible paths ending in a given city, iteratively increasing the network size using the Held-Karp algorithm. \\
\hdashline
\texttt{FD\_greedy.m} & Greedy algorithm increases the path size by including the nearest city. \\
\hdashline
\texttt{FD\_LPTSP.m} &  Integer linear programming solver. \\
\hdashline
\texttt{FD\_LPTSPit.m} &  Integer linear programming solver which ignores the cut-set constraint, but does constrain against sub-cycles. \\
\hdashline
\texttt{FD\_stochastic.m} & Random permutations of paths are considered for a given number of trials. \\
\hdashline
\texttt{forcefully\_increasing\_loop.m} & Begins with a small loop, progressively increasing the size of the route by forcefully including a random city by changing the route by the amount. \\
\hdashline
\texttt{greedy\_algorith\_TSP.m} & Greedy algorithm moves to shortest edge, not allowing for sub-loops. \\
\hdashline
\texttt{greedy\_algorith\_TSP\_all.m} & Greedy algorithm moves to shortest edge, not allowing for sub-loops, and uses a specific starting point. \\
\hdashline
\texttt{increasing\_loop.m} & Begins with a small loop, progressively increasing the size of the route by including the city which increases the distance by the minimal amount. \\
\hdashline
\texttt{IntLinProgCutSetTSP.m} & Integer programming method without the cut-set constraint. \\
\hdashline
\texttt{linprogtsp2.m} &  Miller-Tucker-Zemlin  algorithm, uses cut-set constraints. \\
\hdashline
\texttt{nearestneigh.m} &  A greedy nearest neighbours algorithm added the shortest possible edge.  \\
\hdashline
\texttt{optimal\_greedy\_TSP.m} &  A greedy nearest neighbours algorithm using a specific starting point.  \\
\hdashline
\texttt{RG\_stochastic.m} &  Generates random paths iteratively saving the best result for a chosen number of iterations. \\
\hdashline
\texttt{search\_permutations.m} &  Exhaustive search over all path permutations. \\
\hdashline
\texttt{stochastic\_TSP.m} &  Randomly generates paths, using the shortest over a fixed number of iterations. \\
\hdashline
\texttt{tabu\_search.m} &  Performs a Tabu search. \\
\hdashline
\texttt{tsp\_ip\_no\_cut\_set\_oliver.m} & Integer programming solver which allows sub-loops.\\
\hdashline
\texttt{tsp\_lp\_no\_cut\_set\_oliver.m} & Linear programming solver which allows sub loops and partial journeys (non-physical).\\
\texttt{two\_opt\_search.m} &  Performs a 2-opt local search. \\
\hdashline
\texttt{TwoHeadedSnake.m} &  A two headed greedy algorithm for finding a Hamiltonian cycle by adding the nearest two cities iteratively. \\
\hdashline
\texttt{twoopt.m} &  Performs a 2-opt local search. \\
\hdashline
\texttt{edgeupperbound.m} & Adds the cheapest unused edge that won't create a fork or a loop until a path is formed, then adds in the final edge to create a loop. \\
\hdashline
\texttt{FD\_bruteForce.m} & Explores all possible paths recursively tracking the total distance of smaller networks. \\
\hdashline
\texttt{FD\_dynamicProgramming.m} & Explores all possible paths ending in a given city, iteratively increasing the network size using the Held-Karp algorithm. \\
\hdashline
\texttt{FD\_greedy.m} & Greedy algorithm increases the path size by including the nearest city. \\
\hdashline
\texttt{FD\_LPTSP.m} &  Integer linear programming solver. \\
\hdashline
\texttt{FD\_LPTSPit.m} &  Integer linear programming solver which ignores the cut-set constraint, but does constrain against sub-cycles. \\
\hdashline
\texttt{FD\_stochastic.m} & Random permutations of paths are considered for a given number of trials. \\
\hdashline
\texttt{forcefully\_increasing\_loop.m} & Begins with a small loop, progressively increasing the size of the route by forcefully including a random city by changing the route by the amount. \\
\hdashline
\texttt{greedy\_algorith\_TSP.m} & Greedy algorithm moves to shortest edge, not allowing for sub-loops. \\
\hdashline
\texttt{greedy\_algorith\_TSP\_all.m} & Greedy algorithm moves to shortest edge, not allowing for sub-loops, and uses a specific starting point. \\
\hdashline
\texttt{increasing\_loop.m} & Begins with a small loop, progressively increasing the size of the route by including the city which increases the distance by the minimal amount. \\
\hdashline
\texttt{IntLinProgCutSetTSP.m} & Integer programming method without the cut-set constraint. \\
\hdashline
\texttt{linprogtsp2.m} &  Miller-Tucker-Zemlin  algorithm, uses cut-set constraints. \\
\hdashline
\texttt{nearestneigh.m} &  A greedy nearest neighbours algorithm added the shortest possible edge.  \\
\hdashline
\texttt{optimal\_greedy\_TSP.m} &  A greedy nearest neighbours algorithm using a specific starting point.  \\
\hdashline
\texttt{RG\_stochastic.m} &  Generates random paths iteratively saving the best result for a chosen number of iterations. \\
\hdashline
\texttt{search\_permutations.m} &  Exhaustive search over all path permutations. \\
\hdashline
\texttt{stochastic\_TSP.m} &  Randomly generates paths, using the shortest over a fixed number of iterations. \\
\hdashline
\texttt{tabu\_search.m} &  Performs a Tabu search. \\
\hdashline
\texttt{tsp\_ip\_no\_cut\_set\_oliver.m} & Integer programming solver which allows sub-loops.\\
\hdashline
\texttt{tsp\_lp\_no\_cut\_set\_oliver.m} & Linear programming solver which allows sub loops and partial journeys (non-physical).\\
\texttt{two\_opt\_search.m} &  Performs a 2-opt local search. \\
\hdashline
\texttt{TwoHeadedSnake.m} &  A two headed greedy algorithm for finding a Hamiltonian cycle by adding the nearest two cities iteratively. \\
\hdashline
\texttt{twoopt.m} &  Performs a 2-opt local search. \\
\hline
\end{tabularx}
\caption{Available algorithms for solving the travelling salesman problem, giving the function name and a brief description.}
\label{tab:brief_algorithm_descriptions}
\end{center}
\end{table}    

\end{document}
0

4 Answers 4

2

Here is a way to do it with the ltablex package, which brings the functionalities of longtable to tabularx. Note it has to be loaded before arydshln. I replaced the \multicolumn{1}{c|} with a simple centering.

\documentclass[a4paper, 11pt]{article}

\usepackage{amsmath} % Nice maths symbols.
\usepackage{amssymb} % Nice variable symbols.

\usepackage{ltablex} % Tables with justified columns. long tabularx
\usepackage{array} % Allow for custom column widths in tables.
\usepackage{arydshln} % Dashed lines using \hdashline \cdashline
\usepackage{bbm} % Gives Blackboard fonts.
\usepackage{bm} % Bold math symbols.
\usepackage[margin=10pt,font=small,labelfont=bf,labelsep=endash]{caption} % Caption figures and tables nicely.
\usepackage{enumitem} % Nice listing options in itemize and enumerate.
\usepackage{esdiff} % Gives nice differential operators.
\usepackage{esvect} % Gives nice vector arrows.
\usepackage{float} % Nice figure placement.
\usepackage{geometry} % Use nice margins.
\usepackage{graphicx} % Include figures.
\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue,citecolor=blue,anchorcolor=blue]{hyperref} % Colour links.
\usepackage{indentfirst} % Indents the first paragraph.
\usepackage{letltxmacro} % For defining a nice SQRT symbol.
\usepackage{multirow} % Nice table cells spanning many rows.
\usepackage{multicol} % If I want to use multiple columns.
\usepackage[numbers, sort&compress]{natbib} % Nice references.
\usepackage{physics} % Nice partial derivatives and BRAKET notation.
\usepackage{subcaption} % Side by side figures.
\usepackage{tikz} % For drawing pictures.

% Gives nice margins., showframe
\geometry{margin=20mm}

% Removes hyphenation
\tolerance=1
\emergencystretch=\maxdimen
\hyphenpenalty=10000
\hbadness=10000

% Custom column widths using C{2cm}, L, R, etc.
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}

{\footnotesize\setlength\extrarowheight{1.5pt}\keepXColumns
% Try to input a short description (no more than 1 or 2 lines) of algorithms in alphabetical order.
\begin{tabularx}{\textwidth}{|L{0.4\textwidth}| >{\arraybackslash}X|}
\caption{Available algorithms for solving the travelling salesman problem, giving the function name and a brief description.}
\label{tab:brief_algorithm_descriptions}\\
\hline
\centering Algorithm % use \texttt{text} instead of \verb|text| to allow line breaks for long function names.
& \centering Description \tabularnewline
\hline
\endfirsthead
\hline
 \centering Algorithm % use \texttt{text} instead of \verb|text| to allow line breaks for long function names.
& \centering Description \tabularnewline
\hline
\endhead
\multicolumn{2}{r}{\em To be continued}
 \endfoot
\hline
 \endlastfoot
 \texttt{edgeupperbound.m} & Adds the cheapest unused edge that won't create a fork or a loop until a path is formed, then adds in the final edge to create a loop. \\
\hdashline
\texttt{FD\_bruteForce.m} & Explores all possible paths recursively tracking the total distance of smaller networks. \\
\hdashline
\texttt{FD\_dynamicProgramming.m} & Explores all possible paths ending in a given city, iteratively increasing the network size using the Held-Karp algorithm. \\
\hdashline
\texttt{FD\_greedy.m} & Greedy algorithm increases the path size by including the nearest city. \\
\hdashline
\texttt{FD\_LPTSP.m} & Integer linear programming solver. \\
\hdashline
\texttt{FD\_LPTSPit.m} & Integer linear programming solver which ignores the cut-set constraint, but does constrain against sub-cycles. \\
\hdashline
\texttt{FD\_stochastic.m} & Random permutations of paths are considered for a given number of trials. \\
\hdashline
\texttt{forcefully\_increasing\_loop.m} & Begins with a small loop, progressively increasing the size of the route by forcefully including a random city by changing the route by the amount. \\
\hdashline
\texttt{greedy\_algorith\_TSP.m} & Greedy algorithm moves to shortest edge, not allowing for sub-loops. \\
\hdashline
\texttt{greedy\_algorith\_TSP\_all.m} & Greedy algorithm moves to shortest edge, not allowing for sub-loops, and uses a specific starting point. \\
\hdashline
\texttt{increasing\_loop.m} & Begins with a small loop, progressively increasing the size of the route by including the city which increases the distance by the minimal amount. \\
\hdashline
\texttt{IntLinProgCutSetTSP.m} & Integer programming method without the cut-set constraint. \\
\hdashline
\texttt{linprogtsp2.m} & Miller-Tucker-Zemlin algorithm, uses cut-set constraints. \\
\hdashline
\texttt{nearestneigh.m} & A greedy nearest neighbours algorithm added the shortest possible edge. \\
\hdashline
\texttt{optimal\_greedy\_TSP.m} & A greedy nearest neighbours algorithm using a specific starting point. \\
\hdashline
\texttt{RG\_stochastic.m} & Generates random paths iteratively saving the best result for a chosen number of iterations. \\
\hdashline
\texttt{search\_permutations.m} & Exhaustive search over all path permutations. \\
\hdashline
\texttt{stochastic\_TSP.m} & Randomly generates paths, using the shortest over a fixed number of iterations. \\
\hdashline
\texttt{tabu\_search.m} & Performs a Tabu search. \\
\hdashline
\texttt{tsp\_ip\_no\_cut\_set\_oliver.m} & Integer programming solver which allows sub-loops.\\
\hdashline
\texttt{tsp\_lp\_no\_cut\_set\_oliver.m} & Linear programming solver which allows sub loops and partial journeys (non-physical).\\
\texttt{two\_opt\_search.m} & Performs a 2-opt local search. \\
\hdashline
\texttt{TwoHeadedSnake.m} & A two headed greedy algorithm for finding a Hamiltonian cycle by adding the nearest two cities iteratively. \\
\hdashline
\texttt{twoopt.m} & Performs a 2-opt local search. \\
\hdashline
\texttt{edgeupperbound.m} & Adds the cheapest unused edge that won't create a fork or a loop until a path is formed, then adds in the final edge to create a loop. \\
\hdashline
\texttt{FD\_bruteForce.m} & Explores all possible paths recursively tracking the total distance of smaller networks. \\
\hdashline
\texttt{FD\_dynamicProgramming.m} & Explores all possible paths ending in a given city, iteratively increasing the network size using the Held-Karp algorithm. \\
\hdashline
\texttt{FD\_greedy.m} & Greedy algorithm increases the path size by including the nearest city. \\
\hdashline
\texttt{FD\_LPTSP.m} & Integer linear programming solver. \\
\hdashline
\texttt{FD\_LPTSPit.m} & Integer linear programming solver which ignores the cut-set constraint, but does constrain against sub-cycles. \\
\hdashline
\texttt{FD\_stochastic.m} & Random permutations of paths are considered for a given number of trials. \\
\hdashline
\texttt{forcefully\_increasing\_loop.m} & Begins with a small loop, progressively increasing the size of the route by forcefully including a random city by changing the route by the amount. \\
\hdashline
\texttt{greedy\_algorith\_TSP.m} & Greedy algorithm moves to shortest edge, not allowing for sub-loops. \\
\hdashline
\texttt{greedy\_algorith\_TSP\_all.m} & Greedy algorithm moves to shortest edge, not allowing for sub-loops, and uses a specific starting point. \\
\hdashline
\texttt{increasing\_loop.m} & Begins with a small loop, progressively increasing the size of the route by including the city which increases the distance by the minimal amount. \\
\hdashline
\texttt{IntLinProgCutSetTSP.m} & Integer programming method without the cut-set constraint. \\
\hdashline
\texttt{linprogtsp2.m} & Miller-Tucker-Zemlin algorithm, uses cut-set constraints. \\
\hdashline
\texttt{nearestneigh.m} & A greedy nearest neighbours algorithm added the shortest possible edge. \\
\hdashline
\texttt{optimal\_greedy\_TSP.m} & A greedy nearest neighbours algorithm using a specific starting point. \\
\hdashline
\texttt{RG\_stochastic.m} & Generates random paths iteratively saving the best result for a chosen number of iterations. \\
\hdashline
\texttt{search\_permutations.m} & Exhaustive search over all path permutations. \\
\hdashline
\texttt{stochastic\_TSP.m} & Randomly generates paths, using the shortest over a fixed number of iterations. \\
\hdashline
\texttt{tabu\_search.m} & Performs a Tabu search. \\
\hdashline
\texttt{tsp\_ip\_no\_cut\_set\_oliver.m} & Integer programming solver which allows sub-loops.\\
\hdashline
\texttt{tsp\_lp\_no\_cut\_set\_oliver.m} & Linear programming solver which allows sub loops and partial journeys (non-physical).\\
\texttt{two\_opt\_search.m} & Performs a 2-opt local search. \\
\hdashline
\texttt{TwoHeadedSnake.m} & A two headed greedy algorithm for finding a Hamiltonian cycle by adding the nearest two cities iteratively. \\
\hdashline
\texttt{twoopt.m} & Performs a 2-opt local search.
\end{tabularx}}

\end{document} 

enter image description here

enter image description here

2

Some comments:

  • You mustn't nest a longtable inside a table environment.

  • If you're going to use a longtable, don't ignore the need to provided material for the \endfirsthead, \endhead, \endfoot, and \endlastfoot markers.

  • With a multi-page table, it's customary to provide the table caption at the top rather than at the bottom of the table.

  • I don't think it would be right to allow linebreaks for the material in the first column. Thus, I suggest you use the plain l column type for the first column.

  • I'd give the tabular material a more open look by removing all \hdashline instructions, replacing them with a bit more whitespace. The center vertical line seems like it's unneeded.

  • Since all entries in the first column (other than the header material) should be typeset using monospaced font, you can save yourself a lot of typing of \textt{...} "wrappers" by changing the column specification from l to >{\ttfamily}l.

enter image description here

\documentclass[a4paper, 11pt]{article}
% I've condensed the preamble to the bare mininum.
\usepackage{array} 
\usepackage[margin=10pt,font=small,labelfont=bf,labelsep=endash]{caption} 
\usepackage{longtable}
\usepackage[margin=20mm]{geometry} 
\newcolumntype{L}[2]{>{\raggedright\arraybackslash}p{#1}}

\begin{document}
\begingroup
\setlength\extrarowheight{3pt} % for a more open look
\small
\begin{longtable}{|>{\ttfamily}l L{0.62\textwidth}|}

%% header and footer material

\caption{Available algorithms for solving the travelling salesman problem, giving the function name and a brief description.}
\label{tab:brief_algorithm_descriptions}\\
\hline 
\multicolumn{1}{|l}{Algorithm} & Description \\
\hline 
\endfirsthead

\multicolumn{2}{l}{Table \ref{tab:brief_algorithm_descriptions}, continued}\\[2ex]
\hline 
\multicolumn{1}{|l}{Algorithm} & Description \\
\hline 
\endhead

\hline
\multicolumn{2}{r}{\em Continued on following page}\\
\endfoot

\hline
\endlastfoot

%% body of longtable

edgeupperbound.m & Adds the cheapest unused edge that won't create a fork or a loop until a path is formed, then adds in the final edge to create a loop. \\

FD\_bruteForce.m & Explores all possible paths recursively tracking the total distance of smaller networks. \\

FD\_dynamicProgramming.m & Explores all possible paths ending in a given city, iteratively increasing the network size using the Held-Karp algorithm. \\

FD\_greedy.m & Greedy algorithm increases the path size by including the nearest city. \\

FD\_LPTSP.m &  Integer linear programming solver. \\

FD\_LPTSPit.m &  Integer linear programming solver which ignores the cut-set constraint, but does constrain against sub-cycles. \\

FD\_stochastic.m & Random permutations of paths are considered for a given number of trials. \\

forcefully\_increasing\_loop.m & Begins with a small loop, progressively increasing the size of the route by forcefully including a random city by changing the route by the amount. \\

greedy\_algorith\_TSP.m & Greedy algorithm moves to shortest edge, not allowing for sub-loops. \\

greedy\_algorith\_TSP\_all.m & Greedy algorithm moves to shortest edge, not allowing for sub-loops, and uses a specific starting point. \\

increasing\_loop.m & Begins with a small loop, progressively increasing the size of the route by including the city which increases the distance by the minimal amount. \\

IntLinProgCutSetTSP.m & Integer programming method without the cut-set constraint. \\

linprogtsp2.m &  Miller-Tucker-Zemlin  algorithm, uses cut-set constraints. \\

nearestneigh.m &  A greedy nearest neighbours algorithm added the shortest possible edge.  \\

optimal\_greedy\_TSP.m &  A greedy nearest neighbours algorithm using a specific starting point.  \\

RG\_stochastic.m &  Generates random paths iteratively saving the best result for a chosen number of iterations. \\

search\_permutations.m &  Exhaustive search over all path permutations. \\

stochastic\_TSP.m &  Randomly generates paths, using the shortest over a fixed number of iterations. \\

tabu\_search.m &  Performs a Tabu search. \\

tsp\_ip\_no\_cut\_set\_oliver.m & Integer programming solver which allows sub-loops.\\

tsp\_lp\_no\_cut\_set\_oliver.m & Linear programming solver which allows sub loops and partial journeys (non-physical).\\
two\_opt\_search.m &  Performs a 2-opt local search. \\

TwoHeadedSnake.m &  A two headed greedy algorithm for finding a Hamiltonian cycle by adding the nearest two cities iteratively. \\

twoopt.m &  Performs a 2-opt local search. \\

edgeupperbound.m & Adds the cheapest unused edge that won't create a fork or a loop until a path is formed, then adds in the final edge to create a loop. \\

FD\_bruteForce.m & Explores all possible paths recursively tracking the total distance of smaller networks. \\

FD\_dynamicProgramming.m & Explores all possible paths ending in a given city, iteratively increasing the network size using the Held-Karp algorithm. \\

FD\_greedy.m & Greedy algorithm increases the path size by including the nearest city. \\

FD\_LPTSP.m &  Integer linear programming solver. \\

FD\_LPTSPit.m &  Integer linear programming solver which ignores the cut-set constraint, but does constrain against sub-cycles. \\

FD\_stochastic.m & Random permutations of paths are considered for a given number of trials. \\

forcefully\_increasing\_loop.m & Begins with a small loop, progressively increasing the size of the route by forcefully including a random city by changing the route by the amount. \\

greedy\_algorith\_TSP.m & Greedy algorithm moves to shortest edge, not allowing for sub-loops. \\

greedy\_algorith\_TSP\_all.m & Greedy algorithm moves to shortest edge, not allowing for sub-loops, and uses a specific starting point. \\

increasing\_loop.m & Begins with a small loop, progressively increasing the size of the route by including the city which increases the distance by the minimal amount. \\

IntLinProgCutSetTSP.m & Integer programming method without the cut-set constraint. \\

linprogtsp2.m &  Miller-Tucker-Zemlin  algorithm, uses cut-set constraints. \\

nearestneigh.m &  A greedy nearest neighbours algorithm added the shortest possible edge.  \\

optimal\_greedy\_TSP.m &  A greedy nearest neighbours algorithm using a specific starting point.  \\

RG\_stochastic.m &  Generates random paths iteratively saving the best result for a chosen number of iterations. \\

search\_permutations.m &  Exhaustive search over all path permutations. \\

stochastic\_TSP.m &  Randomly generates paths, using the shortest over a fixed number of iterations. \\

tabu\_search.m &  Performs a Tabu search. \\

tsp\_ip\_no\_cut\_set\_oliver.m & Integer programming solver which allows sub-loops.\\

tsp\_lp\_no\_cut\_set\_oliver.m & Linear programming solver which allows sub loops and partial journeys (non-physical).\\
two\_opt\_search.m &  Performs a 2-opt local search. \\

TwoHeadedSnake.m &  A two headed greedy algorithm for finding a Hamiltonian cycle by adding the nearest two cities iteratively. \\

twoopt.m &  Performs a 2-opt local search. \\

\end{longtable}
\endgroup
\end{document}
1

Use longtabu with as column specification {|X[4,l]|X[6,j]|} (first column left alighned, 40%, second column justified, 60%).

Don't use arydshln as it clashes with tabu, but define \hdasline in terms of \tabucline. It could use a bit more spacing around the dash lines; unfortunately tabu doesn't do this well with multiline cells.

Set up repeating header on each page.

Here is your adapted example. Only a few edits were necessary.

\documentclass[a4paper, 11pt]{article}

\usepackage{amsmath} % Nice maths symbols.
\usepackage{amssymb} % Nice variable symbols.
\usepackage{array} % Allow for custom column widths in tables.
\usepackage{bbm} % Gives Blackboard fonts.
\usepackage{bm} % Bold math symbols.
\usepackage[margin=10pt,font=small,labelfont=bf,labelsep=endash]{caption} % Caption figures and tables nicely.
\usepackage{enumitem} % Nice listing options in itemize and enumerate.
\usepackage{esdiff} % Gives nice differential operators.
\usepackage{esvect} % Gives nice vector arrows.
\usepackage{float} % Nice figure placement.
\usepackage{geometry} % Use nice margins.
\usepackage{graphicx} % Include figures.
\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue,citecolor=blue,anchorcolor=blue]{hyperref} % Colour links.
\usepackage{indentfirst} % Indents the first paragraph.
\usepackage{letltxmacro} % For defining a nice SQRT symbol.
\usepackage{multirow} % Nice table cells spanning many rows.
\usepackage{multicol} % If I want to use multiple columns.
\usepackage[numbers, sort&compress]{natbib} % Nice references.
\usepackage{physics} % Nice partial derivatives and BRAKET notation.
\usepackage{subcaption} % Side by side figures.
%\usepackage{tabularx} % Don't use tabularx
\usepackage{longtable,tabu} % Use longtabu instead
\usepackage{tikz} % For drawing pictures.
%\usepackage{arydshln} % Don't use arydshln (clashes with tabu).
\newcommand\hdashline{\tabucline[\arrayrulewidth on 4pt off 4pt]}

% Gives nice margins.
\geometry{left=20mm, right=20mm, top=20mm, bottom=20mm}

% Removes hyphenation
\tolerance=1
\emergencystretch=\maxdimen
\hyphenpenalty=10000
\hbadness=10000

% Custom column widths using C{2cm}, L, R, etc.
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}

\footnotesize
% Try to input a short description (no more than 1 or 2 lines) of algorithms in alphabetical order.
\begin{longtabu} to \textwidth {|X[4,l]|X[6,j]|}
\hline 
\multicolumn{1}{|c|}{Algorithm}  % use \texttt{text} instead of \verb|text| to allow line breaks for long function names.
& \multicolumn{1}{c|}{Description} \\
\hline \endhead
\texttt{edgeupperbound.m} & Adds the cheapest unused edge that won't create a fork or a loop until a path is formed, then adds in the final edge to create a loop. \\
\hdashline
\texttt{FD\_bruteForce.m} & Explores all possible paths recursively tracking the total distance of smaller networks. \\
\hdashline
\texttt{FD\_dynamicProgramming.m} & Explores all possible paths ending in a given city, iteratively increasing the network size using the Held-Karp algorithm. \\
\hdashline
\texttt{FD\_greedy.m} & Greedy algorithm increases the path size by including the nearest city. \\
\hdashline
\texttt{FD\_LPTSP.m} &  Integer linear programming solver. \\
\hdashline
\texttt{FD\_LPTSPit.m} &  Integer linear programming solver which ignores the cut-set constraint, but does constrain against sub-cycles. \\
\hdashline
\texttt{FD\_stochastic.m} & Random permutations of paths are considered for a given number of trials. \\
\hdashline
\texttt{forcefully\_increasing\_loop.m} & Begins with a small loop, progressively increasing the size of the route by forcefully including a random city by changing the route by the amount. \\
\hdashline
\texttt{greedy\_algorith\_TSP.m} & Greedy algorithm moves to shortest edge, not allowing for sub-loops. \\
\hdashline
\texttt{greedy\_algorith\_TSP\_all.m} & Greedy algorithm moves to shortest edge, not allowing for sub-loops, and uses a specific starting point. \\
\hdashline
\texttt{increasing\_loop.m} & Begins with a small loop, progressively increasing the size of the route by including the city which increases the distance by the minimal amount. \\
\hdashline
\texttt{IntLinProgCutSetTSP.m} & Integer programming method without the cut-set constraint. \\
\hdashline
\texttt{linprogtsp2.m} &  Miller-Tucker-Zemlin  algorithm, uses cut-set constraints. \\
\hdashline
\texttt{nearestneigh.m} &  A greedy nearest neighbours algorithm added the shortest possible edge.  \\
\hdashline
\texttt{optimal\_greedy\_TSP.m} &  A greedy nearest neighbours algorithm using a specific starting point.  \\
\hdashline
\texttt{RG\_stochastic.m} &  Generates random paths iteratively saving the best result for a chosen number of iterations. \\
\hdashline
\texttt{search\_permutations.m} &  Exhaustive search over all path permutations. \\
\hdashline
\texttt{stochastic\_TSP.m} &  Randomly generates paths, using the shortest over a fixed number of iterations. \\
\hdashline
\texttt{tabu\_search.m} &  Performs a Tabu search. \\
\hdashline
\texttt{tsp\_ip\_no\_cut\_set\_oliver.m} & Integer programming solver which allows sub-loops.\\
\hdashline
\texttt{tsp\_lp\_no\_cut\_set\_oliver.m} & Linear programming solver which allows sub loops and partial journeys (non-physical).\\
\texttt{two\_opt\_search.m} &  Performs a 2-opt local search. \\
\hdashline
\texttt{TwoHeadedSnake.m} &  A two headed greedy algorithm for finding a Hamiltonian cycle by adding the nearest two cities iteratively. \\
\hdashline
\texttt{twoopt.m} &  Performs a 2-opt local search. \\
\hdashline
\texttt{edgeupperbound.m} & Adds the cheapest unused edge that won't create a fork or a loop until a path is formed, then adds in the final edge to create a loop. \\
\hdashline
\texttt{FD\_bruteForce.m} & Explores all possible paths recursively tracking the total distance of smaller networks. \\
\hdashline
\texttt{FD\_dynamicProgramming.m} & Explores all possible paths ending in a given city, iteratively increasing the network size using the Held-Karp algorithm. \\
\hdashline
\texttt{FD\_greedy.m} & Greedy algorithm increases the path size by including the nearest city. \\
\hdashline
\texttt{FD\_LPTSP.m} &  Integer linear programming solver. \\
\hdashline
\texttt{FD\_LPTSPit.m} &  Integer linear programming solver which ignores the cut-set constraint, but does constrain against sub-cycles. \\
\hdashline
\texttt{FD\_stochastic.m} & Random permutations of paths are considered for a given number of trials. \\
\hdashline
\texttt{forcefully\_increasing\_loop.m} & Begins with a small loop, progressively increasing the size of the route by forcefully including a random city by changing the route by the amount. \\
\hdashline
\texttt{greedy\_algorith\_TSP.m} & Greedy algorithm moves to shortest edge, not allowing for sub-loops. \\
\hdashline
\texttt{greedy\_algorith\_TSP\_all.m} & Greedy algorithm moves to shortest edge, not allowing for sub-loops, and uses a specific starting point. \\
\hdashline
\texttt{increasing\_loop.m} & Begins with a small loop, progressively increasing the size of the route by including the city which increases the distance by the minimal amount. \\
\hdashline
\texttt{IntLinProgCutSetTSP.m} & Integer programming method without the cut-set constraint. \\
\hdashline
\texttt{linprogtsp2.m} &  Miller-Tucker-Zemlin  algorithm, uses cut-set constraints. \\
\hdashline
\texttt{nearestneigh.m} &  A greedy nearest neighbours algorithm added the shortest possible edge.  \\
\hdashline
\texttt{optimal\_greedy\_TSP.m} &  A greedy nearest neighbours algorithm using a specific starting point.  \\
\hdashline
\texttt{RG\_stochastic.m} &  Generates random paths iteratively saving the best result for a chosen number of iterations. \\
\hdashline
\texttt{search\_permutations.m} &  Exhaustive search over all path permutations. \\
\hdashline
\texttt{stochastic\_TSP.m} &  Randomly generates paths, using the shortest over a fixed number of iterations. \\
\hdashline
\texttt{tabu\_search.m} &  Performs a Tabu search. \\
\hdashline
\texttt{tsp\_ip\_no\_cut\_set\_oliver.m} & Integer programming solver which allows sub-loops.\\
\hdashline
\texttt{tsp\_lp\_no\_cut\_set\_oliver.m} & Linear programming solver which allows sub loops and partial journeys (non-physical).\\
\texttt{two\_opt\_search.m} &  Performs a 2-opt local search. \\
\hdashline
\texttt{TwoHeadedSnake.m} &  A two headed greedy algorithm for finding a Hamiltonian cycle by adding the nearest two cities iteratively. \\
\hdashline
\texttt{twoopt.m} &  Performs a 2-opt local search. \\
\hline 
\caption{Available algorithms for solving the travelling salesman problem, giving the function name and a brief description.}
\label{tab:brief_algorithm_descriptions}
\end{longtabu}

\end{document}
1

You are creating a table inside another table in your code.

If I have understood it right, this code is doing what you want:

\documentclass[a4paper, 11pt]{article}

% I removed some packages from the list which are not needed for this table
\usepackage{longtable,ltablex}
\usepackage{array}
\usepackage{arydshln}
\usepackage[margin=10pt,font=small,labelfont=bf,labelsep=endash]{caption} % Caption figures and tables nicely.
\usepackage{geometry}
\usepackage{multirow}
\usepackage{multicol}

% Gives nice margins.
\geometry{left=20mm, right=20mm, top=20mm, bottom=20mm}

% Custom column widths using C{2cm}, L, R, etc.
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}m{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}m{#1}}

\begin{document}

\begin{center}
%\footnotesize
\renewcommand{\arraystretch}{1.1} % some stretching (better layout)
\begin{tabularx}{\textwidth}{|L{0.4\textwidth}|X|}
\hline 
\multicolumn{1}{|c|}{Algorithm} & \multicolumn{1}{c|}{Description} \\
\hline 
\texttt{edgeupperbound.m} & Adds the cheapest unused edge that won't create a fork or a loop until a path is formed, then adds in the final edge to create a loop. \\
\hdashline
\texttt{FD\_bruteForce.m} & Explores all possible paths recursively tracking the total distance of smaller networks. \\
\hdashline
\texttt{FD\_dynamicProgramming.m} & Explores all possible paths ending in a given city, iteratively increasing the network size using the Held-Karp algorithm. \\
\hdashline
\texttt{FD\_greedy.m} & Greedy algorithm increases the path size by including the nearest city. \\
\hdashline
\texttt{FD\_LPTSP.m} &  Integer linear programming solver. \\
\hdashline
\texttt{FD\_LPTSPit.m} &  Integer linear programming solver which ignores the cut-set constraint, but does constrain against sub-cycles. \\
\hdashline
\texttt{FD\_stochastic.m} & Random permutations of paths are considered for a given number of trials. \\
\hdashline
\texttt{forcefully\_increasing\_loop.m} & Begins with a small loop, progressively increasing the size of the route by forcefully including a random city by changing the route by the amount. \\
\hdashline
\texttt{greedy\_algorith\_TSP.m} & Greedy algorithm moves to shortest edge, not allowing for sub-loops. \\
\hdashline
\texttt{greedy\_algorith\_TSP\_all.m} & Greedy algorithm moves to shortest edge, not allowing for sub-loops, and uses a specific starting point. \\
\hdashline
\texttt{increasing\_loop.m} & Begins with a small loop, progressively increasing the size of the route by including the city which increases the distance by the minimal amount. \\
\hdashline
\texttt{IntLinProgCutSetTSP.m} & Integer programming method without the cut-set constraint. \\
\hdashline
\texttt{linprogtsp2.m} &  Miller-Tucker-Zemlin  algorithm, uses cut-set constraints. \\
\hdashline
\texttt{nearestneigh.m} &  A greedy nearest neighbours algorithm added the shortest possible edge.  \\
\hdashline
\texttt{optimal\_greedy\_TSP.m} &  A greedy nearest neighbours algorithm using a specific starting point.  \\
\hdashline
\texttt{RG\_stochastic.m} &  Generates random paths iteratively saving the best result for a chosen number of iterations. \\
\hdashline
\texttt{search\_permutations.m} &  Exhaustive search over all path permutations. \\
\hdashline
\texttt{stochastic\_TSP.m} &  Randomly generates paths, using the shortest over a fixed number of iterations. \\
\hdashline
\texttt{tabu\_search.m} &  Performs a Tabu search. \\
\hdashline
\texttt{tsp\_ip\_no\_cut\_set\_oliver.m} & Integer programming solver which allows sub-loops.\\
\hdashline
\texttt{tsp\_lp\_no\_cut\_set\_oliver.m} & Linear programming solver which allows sub loops and partial journeys (non-physical).\\
\texttt{two\_opt\_search.m} &  Performs a 2-opt local search. \\
\hdashline
\texttt{TwoHeadedSnake.m} &  A two headed greedy algorithm for finding a Hamiltonian cycle by adding the nearest two cities iteratively. \\
\hdashline
\texttt{twoopt.m} &  Performs a 2-opt local search. \\
\hdashline
\texttt{edgeupperbound.m} & Adds the cheapest unused edge that won't create a fork or a loop until a path is formed, then adds in the final edge to create a loop. \\
\hdashline
\texttt{FD\_bruteForce.m} & Explores all possible paths recursively tracking the total distance of smaller networks. \\
\hdashline
\texttt{FD\_dynamicProgramming.m} & Explores all possible paths ending in a given city, iteratively increasing the network size using the Held-Karp algorithm. \\
\hdashline
\texttt{FD\_greedy.m} & Greedy algorithm increases the path size by including the nearest city. \\
\hdashline
\texttt{FD\_LPTSP.m} &  Integer linear programming solver. \\
\hdashline
\texttt{FD\_LPTSPit.m} &  Integer linear programming solver which ignores the cut-set constraint, but does constrain against sub-cycles. \\
\hdashline
\texttt{FD\_stochastic.m} & Random permutations of paths are considered for a given number of trials. \\
\hdashline
\texttt{forcefully\_increasing\_loop.m} & Begins with a small loop, progressively increasing the size of the route by forcefully including a random city by changing the route by the amount. \\
\hdashline
\texttt{greedy\_algorith\_TSP.m} & Greedy algorithm moves to shortest edge, not allowing for sub-loops. \\
\hdashline
\texttt{greedy\_algorith\_TSP\_all.m} & Greedy algorithm moves to shortest edge, not allowing for sub-loops, and uses a specific starting point. \\
\hdashline
\texttt{increasing\_loop.m} & Begins with a small loop, progressively increasing the size of the route by including the city which increases the distance by the minimal amount. \\
\hdashline
\texttt{IntLinProgCutSetTSP.m} & Integer programming method without the cut-set constraint. \\
\hdashline
\texttt{linprogtsp2.m} &  Miller-Tucker-Zemlin  algorithm, uses cut-set constraints. \\
\hdashline
\texttt{nearestneigh.m} &  A greedy nearest neighbours algorithm added the shortest possible edge.  \\
\hdashline
\texttt{optimal\_greedy\_TSP.m} &  A greedy nearest neighbours algorithm using a specific starting point.  \\
\hdashline
\texttt{RG\_stochastic.m} &  Generates random paths iteratively saving the best result for a chosen number of iterations. \\
\hdashline
\texttt{search\_permutations.m} &  Exhaustive search over all path permutations. \\
\hdashline
\texttt{stochastic\_TSP.m} &  Randomly generates paths, using the shortest over a fixed number of iterations. \\
\hdashline
\texttt{tabu\_search.m} &  Performs a Tabu search. \\
\hdashline
\texttt{tsp\_ip\_no\_cut\_set\_oliver.m} & Integer programming solver which allows sub-loops.\\
\hdashline
\texttt{tsp\_lp\_no\_cut\_set\_oliver.m} & Linear programming solver which allows sub loops and partial journeys (non-physical).\\
\texttt{two\_opt\_search.m} &  Performs a 2-opt local search. \\
\hdashline
\texttt{TwoHeadedSnake.m} &  A two headed greedy algorithm for finding a Hamiltonian cycle by adding the nearest two cities iteratively. \\
\hdashline
\texttt{twoopt.m} &  Performs a 2-opt local search. \\
\hline
\caption{Available algorithms for solving the travelling salesman problem, giving the function name and a brief description.}
\label{tab:brief_algorithm_descriptions}
\end{tabularx}
\renewcommand{\arraystretch}{1} % reset stretching
\end{center}

\end{document}
4
  • Is there a way to avoid having to replace all the `\`? Also I would like to keep the second column justified is possible.
    – oliversm
    Dec 11, 2016 at 13:22
  • @oliversm I have updated my answer using the ltablex package now which is a combination of the longtable and the tabularx package. Additionally I made a small change to the custom column types to avoid having to write \tabularnewline.
    – epR8GaYuh
    Dec 11, 2016 at 13:43
  • This doesn't compile. ERROR: Package array Error: Illegal pream-token (\textwidth): c' used. l.25 \begin{longtable}{\textwidth} {|L{0.4\textwidth}|X|}` Dec 11, 2016 at 15:01
  • @PietvanOostrum Thank you for pointing this out. Should be fixed now.
    – epR8GaYuh
    Dec 11, 2016 at 15:24

You must log in to answer this question.

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