PrintTableToLaTeX Source Code:

#############################################################################
#
#F  Function PrintTableToLaTeX(  )
#
# <#GAPDoc Label="PrintTableToLaTeXHeader">
#   
#     
#     
#
#     
#      file containing LaTeX code for a table with entries 
#               from matrix.
#     
#     PrintTableToLaTeX See returns.
#     
#   
# <#/GAPDoc>
#
# METHOD: Run through entries of matrix, create string of commands
#         for a row in a LaTeX table, then print to file.
#
#############################################################################

PrintTableToLaTeX:=function(table, string, title, append)
  local fileName, str,i,j;
  fileName:= Concatenation("LaTeXTable-", string);
  # Append or overwrite any existing files
  if(append = true) then ;
  else PrintTo(fileName, "");
  fi;
  # Preamble for LaTeX table
  AppendTo(fileName, Concatenation(Concatenation(Concatenation("\\begin{table}[htp] 
	\n\\centering \n\\caption{",  title),"} \n\\label{tab:gr} 
	\n\\footnotesize\\setlength{\\tabcolsep}{2.5pt} 
	\n\\begin{tabular}{l@{\\hspace{6pt}} *{", String(Length(table[1]))), "}{c}} 
	\n\\toprule\n"));
  
  str:="";
  
  for i in [1..Length(table)] do
    for j in [1..Length(table[1])] do
      if (IsInt(table[i][j]) = false) then str:=String(table[i][j]);
      else str:= Concatenation(Concatenation(" $ ", String(table[i][j])), " $ ");
      fi;
      
      if (j = Length(table[1])) then str:=Concatenation(str, " \\\\");
      else str:=Concatenation(str, " &");
      fi;
  
      AppendTo(fileName, str); 
    od;
    AppendTo(fileName, "\n");
  od;
  
  AppendTo(fileName, "\\bottomrule \n\\addlinespace \n\\end{tabular} \n\\end{table}\n");
end;