Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

left-align table caption #194

Open
HenrikEckermann opened this issue May 6, 2018 · 6 comments
Open

left-align table caption #194

HenrikEckermann opened this issue May 6, 2018 · 6 comments

Comments

@HenrikEckermann
Copy link

@HenrikEckermann HenrikEckermann commented May 6, 2018

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?

@haozhu233
Copy link
Owner

@haozhu233 haozhu233 commented May 7, 2018

Hi, @HenrikEckermann, this is a feature I have been thinking of for a while (#72). I haven't implemented it but will do it in the near future.

@HenrikEckermann
Copy link
Author

@HenrikEckermann HenrikEckermann commented Jun 5, 2018

Maybe as a temporary solution for those who need this to make tables/figures apa6th style:

For me this worked in Rmarkdown:

  1. 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}
  1. 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!

@haozhu233
Copy link
Owner

@haozhu233 haozhu233 commented Jun 5, 2018

@HenrikEckermann Thanks a lot for posting this solution here! It also helps me think through the case. 👍

@pm321
Copy link

@pm321 pm321 commented Jul 4, 2018

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

@haozhu233
Copy link
Owner

@haozhu233 haozhu233 commented Jul 4, 2018

@randomgambit
Copy link

@randomgambit randomgambit commented Sep 23, 2018

@haozhu233 hello there! any updates on this vital option? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants