A command has been created to fill in a row in the table for ease of use, this command has an optional argument and it would appear that that particular argument messes us the centering of the first column.
I have created a MWE below:
Code: Select all
\documentclass[]{report}
\usepackage{array}
\usepackage{longtable}
% create my new counter
\newcounter{mycounter}
\setcounter{mycounter}{0}
% #1 inc.count
% #2 table column
\newcommand{\doline}[2]
{
\arabic{mycounter} & #2 & ???? \addtocounter{mycounter}{#1} \\
}
% #1 = inc. count
% #2 = table column
\newcommand{\tablelineWORKS}[2]
{
\doline{#1}{#2}
}
% #1 = optional argument
% #2 = inc. count
% #3 = table column
\newcommand{\tablelineNOTWORKS}[3][empty]
{
\doline{#2}{#3}
}
\begin{document}
This long table doesn't work:
\begin{longtable}{>{\centering\arraybackslash}m{1.5cm}>{\centering\arraybackslash}m{6cm}m{2cm}}
\hline
HEADER 1 & HEADER 2 & HEADER 3 \\
\hline
\tablelineWORKS{2}{this line works!}
\tablelineNOTWORKS{2}{BAD LINE! NO optional param}
\tablelineNOTWORKS[xxxx]{2}{BAD LINE! WITH optional param}
\tablelineWORKS{2}{this line works!}
\hline
\end{longtable}
This table is working:
\begin{tabular}{>{\centering\arraybackslash}m{1.5cm}>{\centering\arraybackslash}m{6cm}m{2cm}}
\hline
HEADER 1 & HEADER 2 & HEADER 3 \\
\hline
\tablelineWORKS{2}{this line works!}
\tablelineNOTWORKS{2}{OK! NO optional param}
\tablelineNOTWORKS[xxxx]{2}{OK! WITH optional param}
\tablelineWORKS{2}{this line works!}
\hline
\end{tabular}
This table is not working:
\begin{tabular}{ccc}
\hline
HEADER 1 & HEADER 2 & HEADER 3 \\
\hline
\tablelineWORKS{2}{this line works!}
\tablelineNOTWORKS{2}{BAD LINE! NO optional param}
\tablelineNOTWORKS[xxxx]{2}{BAD LINE! WITH optional param}
\tablelineWORKS{2}{this line works!}
\hline
\end{tabular}
\end{document}
Im sure it has something to do with the fact that the command
\tablelineNOTWORKS
has an optional parameter, but I don't understand why that would cause a problem.I can get round this issue by using two commands instead of one clever one with an optional argument but I would still like to know why the problem exists, if possible.
Any ideas anyone?
Many thanks in advance