I have R code that produces latex code like:
\begin{tabular}{D{.}{.}{7}D{.}{.}{7}}
\toprule
\multicolumn{1}{c}{x} & \multicolumn{1}{c}{y} \\
\midrule
[1, 5) & 1 \\
[1, 5) & 2 \\
[5, 8) & 5 \\
[5, 8) & 7 \\
[8,10] & 8 \\
[8,10] & 10 \\
\bottomrule
\end{tabular}
And this is producing math errors:
! LaTeX Error: Bad math environment delimiter.
How do I prevent this from happening? I'd like the square brackets to be printed as-is since they represent intervals - previously in the office a workaround of switching to a { has been done but it looks terrible!
I've read around but not seen anything specific about preventing latex from entering math-mode. However, I'm new to this so I'm probably using the wrong keywords!
Example
I'm producing the code inside knitr chunks with the following parameters:
<<tab-example,echo=FALSE,cache=FALSE,results='asis'>>=
example<-data.frame(cbind(x=1:10,y=1:10))
example$x<-cut(example$x,3)
toLatex(example)
@
Packages currently used
\usepackage{fancyhdr,dcolumn,booktabs,float,titlesec}
\usepackage[margin=0.7in]{geometry}
\usepackage[us,12hr]{datetime}
\` in a
tabular` is always assumed to indicate a dimension. if you are instead presenting data, always wrap the bracketed expression in braces to avoid misinterpretation.{..}
) the ranges or insert something before the first[
on every line? LaTeX gets confused, expecting a length if you follow\\
by[
.{}
before each element.{}
really did the trick. If you'd like to put it as an answer I'll mark it as accepted