3

I'd like to align an xtable figure caption left adjusted with the table, or if that doesn't work, at least centered, because I think it looks kind of stupid a small table being centered and the corresponding caption being left aligned. Also, left aligning both table and caption is not optimal.

It should be possible using latex.environments = "left", but I get an error message, just like in this post.

I don't think the problem lies in the referencing, because I get the same error message with and without label="myLabel".

Here a MWE:

<<table, echo=FALSE, results='asis'>>=
print(xtable(lm(mpg~hp, data=mtcars), caption="Linear Model", label="myLabel") , caption.placement = "top", latex.environments="left")
@

The error (short form, for long version see this post again):

Missing $ inserted.
Missing delimiter (. inserted)
Missing $ inserted
Missing \right. inserted

Does somebody know a solution? Left aligned with left side of the table or centered, I'd be happy with any solution.

Community
  • 1
  • 1
jmjr
  • 2,090
  • 2
  • 21
  • 31
  • I have the problem. In the meanwhile did you find out the problem using `latex.environments="left"`? – giordano Oct 10 '16 at 09:48

1 Answers1

0

Ok so I found a solution to at least center the table captions, using package caption, specifying

\usepackage[
    singlelinecheck=false,
    justification=centering
]{caption}
jmjr
  • 2,090
  • 2
  • 21
  • 31
  • 1
    For left-justifying the table, use `latex.environments="flushleft"`. See http://stackoverflow.com/a/31898709/3625022. – Clarinetist Jan 17 '17 at 14:26