kableExtra
kableExtra copied to clipboard
left-align table caption
Thanks for this awesome package haozhu233!
I wanted to ask or otherwise note:
Is there a way to left-align the table caption? If I specify a caption, it is always centered above the table. I would prefer this in exactly this way! However, for a paper in APA6th they expect me to leftalign the table caption. Is there a way to do this with kableExtra?
Hi, @HenrikEckermann, this is a feature I have been thinking of for a while (https://github.com/haozhu233/kableExtra/issues/72). I haven't implemented it but will do it in the near future.
Maybe as a temporary solution for those who need this to make tables/figures apa6th style:
For me this worked in Rmarkdown:
- Specify header.tex as follows:
\usepackage{caption}
\DeclareCaptionLabelSeparator*{spaced}{\\[2ex]}
\captionsetup[table]{textfont=it,format=plain,justification=justified,
singlelinecheck=false,labelsep=spaced,skip=0pt}
\captionsetup[figure]{labelsep=period,labelfont=it,justification=justified,
singlelinecheck=false,font=doublespacing}
- Include this in your YAML header:
documentclass: "article"
header-includes:
- \usepackage{booktabs}
- \usepackage{multirow}
- \usepackage{setspace}
- \usepackage{subcaption}
- \usepackage{caption}
- \usepackage{tikz}
- \usepackage{float}
- \usepackage{setspace}
output:
pdf_document:
fig_caption: yes
keep_tex: yes
includes:
in_header: header.tex
Then e.g. a table like this worked for me:
kable(norm_table, booktabs = T, caption = "Normality Statistics", escape = F) %>%
kable_styling(latex_option = c("hold_position"), position = "left")
The escape = F
is not required but was required here for other reasons.
It maybe that not everything is required (e.g. I think kableExtra load booktabs anyway). But this works for me to make tables completely apa6th conform (I struggle though with linebreaks that I need for longer lines in notes but saw new linebreak functionality in kableExtra so maybe I can figure out a way!)
kableExtra is really very useful. Please keep up the good work!
@HenrikEckermann Thanks a lot for posting this solution here! It also helps me think through the case. 👍
KableExtra is fast becoming my preferred way of managing tables in rmarkdown - super package.
Adding to the feature request: would it be possible to include an option to place the caption below the table? Would a reasonable set of options include: Top: right, centre, and left aligned Bottom: right, centre, and left aligned
I do want to check out if it’s possible to change caption location in the next version but I’m not sure if it’s too difficult to achieve. If so, you may want to try out the xtable2kable solution I provided in https://github.com/haozhu233/kableExtra/issues/221 and I do have a plan to include a more completed version of that function in the next version.
For caption alignment, the only way to solve it in latex seems to be through the caption package as Henrik mentioned above. I guess we shouldn’t expect it will work just like positioning your table. On Wed, Jul 4, 2018 at 21:42 pm321 [email protected] wrote:
KableExtra is fast becoming my preferred way of managing tables in rmarkdown - super package.
Adding to the feature request: would it be possible to include an option to place the caption below the table? Would a reasonable set of options include: Top: right, centre, and left aligned Bottom: right, centre, and left aligned
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/haozhu233/kableExtra/issues/194#issuecomment-402483181, or mute the thread https://github.com/notifications/unsubscribe-auth/AGsIvivPFSAH-ywlcXI8IIMh7kTLwIi6ks5uDMZXgaJpZM4T0C4Q .
@haozhu233 hello there! any updates on this vital option? :)
use the follwing command
\usepackage[singlelinecheck=false]{caption}