Align picture to the right
In order to align the image to the right margin, you might want to use foatrow
's \floatsetup[figure]{margins=raggedleft}
command. You can either use it globally by putting it into the preamble or locally as shown in teh following MWE:
\documentclass[12pt,a4paper]{article}
\usepackage[showframe]{geometry}
\usepackage[demo]{graphicx}
\usepackage{lipsum}
\usepackage{floatrow}
\usepackage{caption}
\captionsetup{labelsep=newline,
justification=raggedleft,
singlelinecheck=false,
labelfont=bf,
font=small}
\begin{document}
\lipsum[2]
{\floatsetup[figure]{margins=raggedleft}
\begin{figure}[H]
\floatbox[{\capbeside\thisfloatsetup{capbesideposition={left,center},capbesidewidth=4cm}}]{figure}[\FBwidth]
{\caption{Some caption that spans more than a line and some additional text}}
{\includegraphics[width=5cm]{name}}
\end{figure}}
\begin{figure}[H]
\floatbox[{\capbeside\thisfloatsetup{capbesideposition={left,center},capbesidewidth=4cm}}]{figure}[\FBwidth]
{\caption{Some caption that spans more than a line and some additional text}}
{\includegraphics[width=5cm]{name}}
\end{figure}
\end{document}
Regarding switching from article
to scrartcl
you will recieve the following error message:
Package
caption
Error: The optionlabelsep=newline
does not work with\setcaphanging
(which is set by default).
Looking through the caption
manual, we can find that the default format
of article
and scrartcl
differ:
By adding format=plain
to the \captionsetup
command, we can make the code compilable for scrartcl
as well. Nevertheless, I'd suggest to take a look at the KOMA-script documentation as these document classes already offer ways to customize the look of captions.
Only as a supplement to the answer of @leandris for the KOMA-Script part: The KOMA-Script class provides environments captionbeside
and captionofbeside
.
\documentclass[12pt,a4paper]{scrartcl}
\usepackage{showframe}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{float}% if position H is really needed
\KOMAoption{captions}{nooneline,centeredbeside,leftbeside}
\setcapindent*{0pt}
\setcaptionalignment{r}
\renewcommand\captionformat{}
\addtokomafont{caption}{\small}
\addtokomafont{captionlabel}{\bfseries}
\begin{document}
\lipsum[1]
\begin{figure}[H]
\begin{captionbeside}
{Some caption that spans more than a line and some additional text}%
\includegraphics[width=5cm]{example-image}
\end{captionbeside}
\end{figure}
\lipsum[2]
\begin{figure}[H]
\begin{captionbeside}
{Some caption that spans more than a line and some additional text}%
[l]% caption position
[\dimexpr9cm+10pt\relax]% width of caption and figure
[\dimexpr\linewidth-9cm-10pt\relax]% offset
\includegraphics[width=5cm]{example-image}
\end{captionbeside}
\end{figure}
\end{document}
Result:
Warning: Package floatrow
breaks environment captionbeside
.