You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wrote some code that generates LaTeX or HTML code for custom-made tables. I would very much like to take advantage of \@referencing syntax of bookdown.
It was fairly simple with LaTeX as I had to simply throw in \label{} somewhere in the output.
I am trying to understand how does it work with HTML output. In the md file generated with bookdown::html_document2 a table produced with knitr::kable inserts something like
Table: (\#tab:knitrtable)This is knitr kable table.
Variable num ch f logical
--------- ---- --- --- --------
A 1 a a FALSE
B 2 b b TRUE
C 3 c c TRUE
D 4 d d TRUE
E 5 e e FALSE
See table \@ref(tab:knitrtable).
I tried inserting <caption> tags with the similar structure as the corresponding HTML output from bookdown::html_document2 but it does not work. I am not sure at which stage of document processing bookdown resolves the references.
It will be nice if you can provide a minimal example of what you tried exactly so I don't have to guess. Anyway, I think if your table caption is of this form <caption>(#tab:label), \\@ref(label) should work.
Yes, sorry about the lack of example. The original code would be overwhelming with details so I started to distill a simple example. While doing that I was able to get it to work :D
Thanks for the suggestion! I was mislead by the \ in the Markdown code above.
When run in RMarkdown \@ref(tab:tabletwo) seems to give correct hyperlinked reference with number, but the table caption does not work and in browser looks like (#tab:tabletwo) A table.
it works only for :word_document2: but not for bookdown::pdf_book:
I also tried with @cite{stefc2009partII} ; \cite[@stefc2009partII]}; \cite[@stefc2009partII]} ; \@cite(stefc2009partII) no one works...
I'm very new to LaTeX, Rmd ,and bookdown, I'm using those for writing down my PhD Thesis.
Could you help me, please?
.bib @Article{stefc2009partII,
title={Report of the SGMED-09-03 Working Group on
the Mediterranean Part II},
author={Massimiliano Cardinale, Anna Cheilari, Hans-Joachim Rätz},
journal={EUR - Scientific and Technical Research Reports (STEFC) },
year={2009},
publisher={JRC}
}
Activity
yihui commentedon Mar 20, 2017
It will be nice if you can provide a minimal example of what you tried exactly so I don't have to guess. Anyway, I think if your table caption is of this form
<caption>(#tab:label),\\@ref(label)should work.mbojan commentedon Mar 20, 2017
Yes, sorry about the lack of example. The original code would be overwhelming with details so I started to distill a simple example. While doing that I was able to get it to work :D
Thanks for the suggestion! I was mislead by the
\in the Markdown code above.Here is what works for me (essentially):
The code
and later in Rmarkdown
yihui commentedon Mar 20, 2017
Okay, great!
mbojan commentedon Mar 20, 2017
Well, in fact, I'm still fighting with it. I am trying to hack
htmlTable. See this:gives the following HTML:
When run in RMarkdown
\@ref(tab:tabletwo)seems to give correct hyperlinked reference with number, but the table caption does not work and in browser looks like(#tab:tabletwo) A table.Any ideas?
mbojan commentedon Mar 20, 2017
I did a bit of debugging...
It seems that the caption fails to be updated because the regexp in
parse_fig_labels(bookdown/R/html.R
Line 521 in 4a8a9f5
"^<caption>"so assumes that there are no tag attributes. This fails in my code because the<caption>tag has attributes.Am I correct that the search is done only to check if the
(#tab:label)piece is mentioned within HTML<caption>?Perhaps the regexp could just catch
"^<caption"?mbojan commentedon Mar 20, 2017
I forked, tried, and it fixes the problem. I'm not 100% sure if it does not break anything, but so far so good.
Want a PR?
Modifed caption search in parse_fig_labels() (#376)
yihui commentedon Mar 21, 2017
I don't know if it is going to break anything, either, but I have merged it anyway. If I discover problems in the future, I may revert it. Thanks!
CarolineXGao commentedon Sep 26, 2020
Hi Yihui,
I have a similar issue. Referencing seems to work for html and word but not pdf. Do you know where things might be wrong ?
Thanks
Caroline
This is a reference to Table @ref(tab:tableone).
andreapierucci commentedon Jan 7, 2021
HI, @yihui and @mbojan I have a problem similar to Caroline.
When I use \cite{} in my table in bookdown::pdf_book: like
\begin{tabular}{|l|l|l|l|}
\hline
reference & Charactersitic 1 & Charactersitic 2 & Charactersitic 3 \
\hline
\cite{stefc2009partII} & method xx & method xy & method xz \
\hline
\cite{stefc2009partII} & method yx & method yy & method yz \
\hline
\end{tabular}
it works only for :word_document2: but not for bookdown::pdf_book:
I also tried with @cite{stefc2009partII} ; \cite[@stefc2009partII]}; \cite[@stefc2009partII]} ; \@cite(stefc2009partII) no one works...
I'm very new to LaTeX, Rmd ,and bookdown, I'm using those for writing down my PhD Thesis.
Could you help me, please?
.bib
@Article{stefc2009partII,
title={Report of the SGMED-09-03 Working Group on
the Mediterranean Part II},
author={Massimiliano Cardinale, Anna Cheilari, Hans-Joachim Rätz},
journal={EUR - Scientific and Technical Research Reports (STEFC) },
year={2009},
publisher={JRC}
}
cderv commentedon Apr 1, 2021
Hi @andreapierucci Can you open a new issue following the issue guide https://yihui.org/issue/ ?
Or ask in one of the QA site before if not already done in case you are not sure this is an issue ? Thanks!
github-actions commentedon Sep 29, 2021
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.