Set title for indices on figures and tables

In my figures and tables I need to provide a long description. However for the indices I don't want to have such a long description.
On latex, according to the documentation of \caption I can use:

\caption[Title for index]{Caption of the figure or table}

I tried with several options, but all fail for one reason or another:

[Title]![Caption](pressure.png)
![Title][Caption](pressure.png)
![(#fig:caption) \[Title\]](pressure.png)
![Title](pressure.png [Caption])

Is there a way to set up this on bookdown?
Maybe this is out of the possibilities of bookdown and I should manually edit the .tex file and compile it to pdf ?
How would I do that outside knitr? Although I'm a bit familiar with LaTeX, I'm not sure I would be able to compile with texmaker or similar programs.

Thanks

knitr has a fig.scap option for this I think. See

  • fig.scap : ( NULL ; character) A short caption. This option is only meaningful to LaTeX output. A short caption is inserted in \caption[] , and usually displayed in the “List of Figures” of a PDF document.

It should be

```{r, fig.cap = "Caption", fig.scap = "short caption"}
knitr::include_graphics("pressure.png")
```

This will produce

\begin{figure}
\includegraphics[width=6.67in]{pressure} \caption[short caption]{Caption}\label{fig:unnamed-chunk-1}
\end{figure}

Is this what you are looking for ?

1 Like

For figures:

```{r, fig.cap = "Caption", fig.scap = "short caption"}
knitr::include_graphics("pressure.png")
```

For tables

```{r reference-tab}
kable(table, caption = "Real caption of table", caption.short = "Index's short caption")
```

Sorry, I looked to bookdown-related documentation and didn't thought to look up on knitr's documentation.
This is a nice workaround for figures. Many thanks!

Is possible to do this without using the code block to include a graphic? I'm thinking on tables where I didn't find a way for fig.scap to work as the result is not a figure and the tables generated are different between simple markdown and knitr kable:

| Model 1          | GE  | CGH | Localization |
|------------------|:---:|:---:|:------------:|
| **GE**           |  0  |  0  |      1       |
| **CGH**          |  0  |  0  |      1       |
| **Localization** |  1  |  1  |      0       |

: (#tab:label) Caption


```{r, fig.cap="Real caption of table and index"}
knitr::kable(head(mtcars))
```

```{r, fig.scap="scap table", fig.cap="Real caption of table"}
knitr::kable(head(mtcars))
```

Latex output:

\begin{longtable}[]{@{}lccc@{}}
\caption{\label{tab:label} Caption}\tabularnewline
\toprule
Model 1 & GE & CGH & Localization \\
\midrule
\endfirsthead
\toprule
Model 1 & GE & CGH & Localization \\
\midrule
\endhead
\textbf{GE} & 0 & 0 & 1 \\
\textbf{CGH} & 0 & 0 & 1 \\
\textbf{Localization} & 1 & 1 & 0 \\
\bottomrule
\end{longtable}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{knitr}\SpecialCharTok{::}\FunctionTok{kable}\NormalTok{(}\FunctionTok{head}\NormalTok{(mtcars))}
\end{Highlighting}
\end{Shaded}

\begin{tabular}{l|r|r|r|r|r|r|r|r|r|r|r}
\hline
  & mpg & cyl & disp & hp & drat & wt & qsec & vs & am & gear & carb\\
\hline
Mazda RX4 & 21.0 & 6 & 160 & 110 & 3.90 & 2.620 & 16.46 & 0 & 1 & 4 & 4\\
\hline
Mazda RX4 Wag & 21.0 & 6 & 160 & 110 & 3.90 & 2.875 & 17.02 & 0 & 1 & 4 & 4\\
\hline
Datsun 710 & 22.8 & 4 & 108 & 93 & 3.85 & 2.320 & 18.61 & 1 & 1 & 4 & 1\\
\hline
Hornet 4 Drive & 21.4 & 6 & 258 & 110 & 3.08 & 3.215 & 19.44 & 1 & 0 & 3 & 1\\
\hline
Hornet Sportabout & 18.7 & 8 & 360 & 175 & 3.15 & 3.440 & 17.02 & 0 & 0 & 3 & 2\\
\hline
Valiant & 18.1 & 6 & 225 & 105 & 2.76 & 3.460 & 20.22 & 1 & 0 & 3 & 1\\
\hline
\end{tabular}


\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{knitr}\SpecialCharTok{::}\FunctionTok{kable}\NormalTok{(}\FunctionTok{head}\NormalTok{(mtcars))}
\end{Highlighting}
\end{Shaded}

\begin{tabular}{l|r|r|r|r|r|r|r|r|r|r|r}
\hline
  & mpg & cyl & disp & hp & drat & wt & qsec & vs & am & gear & carb\\
\hline
Mazda RX4 & 21.0 & 6 & 160 & 110 & 3.90 & 2.620 & 16.46 & 0 & 1 & 4 & 4\\
\hline
Mazda RX4 Wag & 21.0 & 6 & 160 & 110 & 3.90 & 2.875 & 17.02 & 0 & 1 & 4 & 4\\
\hline
Datsun 710 & 22.8 & 4 & 108 & 93 & 3.85 & 2.320 & 18.61 & 1 & 1 & 4 & 1\\
\hline
Hornet 4 Drive & 21.4 & 6 & 258 & 110 & 3.08 & 3.215 & 19.44 & 1 & 0 & 3 & 1\\
\hline
Hornet Sportabout & 18.7 & 8 & 360 & 175 & 3.15 & 3.440 & 17.02 & 0 & 0 & 3 & 2\\
\hline
Valiant & 18.1 & 6 & 225 & 105 & 2.76 & 3.460 & 20.22 & 1 & 0 & 3 & 1\\
\hline
\end{tabular}

Edit: I can use kable(caption = "Caption") but it doesn't recognize scap or scaption arguments. But perhaps I should use other packages to create the tables (But I would prefer to avoid re-formatting all the tables I have to be accepted by a package only to be printed).

Found it! I should use caption.short, from 10.1 The function knitr::kable() | R Markdown Cookbook.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.