Bookdown linking & formatting to manually created markdown table

bookdown

#1

I'm working on a bookdown project and I have a few tables that are manually created using Markdown table syntax:

| Tables   |      Are      |  Cool |
|----------|:-------------:|------:|
| col 1 is |  left-aligned | $1600 |
| col 2 is |    centered   |   $12 |
| col 3 is | right-aligned |    $1 |

Table: TablesAreCool

These labels kinda-sorta work. When I build the book to bookdown::pdf_book the table caption ends up on the top of the table with a table number. As I would expect. However I can't figure out how to link to it in the text. Using the example table above, I would have thought I could do this:

see also \@ref(tab:TablesAreCool) for an awesome table example

But that results in just ?? in my final document in either pdf_book or gitbook builds.

How do I link to manually created tables?

In addition, I notice that when I build to bookdown::gitbook my figures are still labeled and link correctly, but my manually created tables still have titles but no longer have table numbers. Is there a work around so that I can have table figures in both pdf and html?


#2

Hi,

To be able to reference your table, you should put the labeled caption before your table and use this syntax:

Table: (\#label) TablesAreCool

Where label must have the prefix tab, e.g. tab:simple-table. You can find more information in the bookdown book https://bookdown.org/yihui/bookdown/tables.html.

So in your example, you should use Table: (\#TablesAreCool) This table is really cool.

Hope this helps.


#3

Thanks for the early morning help, @Desautm. That solves both of the questions I raised. Apparently I had read 90% of that section of Yihui's book but missed that last paragraph. Thanks again.