2

After trying many of the community's proposals and failing to place the title of the figure at the top.

I thought that I could redefine the default figure in latex, specifically the one corresponding to the document class article, if they are different depending on the class.

I saw something similar but now I can't find it.

6
  • Do you have tried caption package? Nov 7, 2021 at 23:08
  • 1
    what do you mean by the title of the figure? in article class figures have captions given by \caption and it is placed where you place it in the source above or below the image depending if \caption is before or after \includegraphics Nov 7, 2021 at 23:17
  • I use rmarkdown and knitr Nov 7, 2021 at 23:22
  • What would be the parameters to define the caption of figures at the top when including the package caption? usepackage[PARAMETERS]{caption} Nov 7, 2021 at 23:43
  • sure but this is a latex question, the default code in article class does not position the caption at all so it's like asking to write two one instead of one two latex does nothing here, it just outputs the caption and image in the order you write them, so it is very hard to answer your question. Nov 7, 2021 at 23:44

2 Answers 2

1

Written in markdown and compiled with knitr, you can have the caption at the top like this:

---
output: 
  pdf_document
header-includes:
  - \usepackage{floatrow}
  - \floatsetup[figure]{capposition=top}
---
```{r message=FALSE, echo=FALSE}
library(ggplot2)
```

```{r fig.cap="Diamonds", message=FALSE, echo=FALSE}
ggplot(data=diamonds,aes(x=price,y=carat,colour=cut)) + geom_point()
```

enter image description here

1

Hope that this is self-explanatory.

\documentclass{article}
% Provides example-image afaik.
\usepackage{graphicx}

% for [H] placement option (force manually defined position)
\usepackage{float}

\begin{document}

\textbf{\figurename~\ref{fig:CaptionAbove}} has the caption \textbf{above} and \textbf{\figurename~\ref{fig:CaptionBelow}} has the caption \textbf{below}.

\begin{figure}[H]
    \centering
    \caption{Caption Above}
    \includegraphics[width=0.75\textwidth]{example-image}
    %\caption{Caption Below}
    \label{fig:CaptionAbove}
\end{figure}

\begin{figure}[H]
    \centering
    %\caption{Caption Above}
    \includegraphics[width=0.75\textwidth]{example-image}
    \caption{Caption Below}
    \label{fig:CaptionBelow}
\end{figure}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .