# Align picture to the right

Consider this 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]

\begin{figure}[H]
\raggedleft
\begin{minipage}{20cm}
\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{minipage}
\end{figure}
\end{document}


This is what I get

As you can see from the command \raggedleft in the code, I was expecting a result which is more like this

How do I achieve this? Also, although this code works perfectly with article class, but if I switch to scrartcl the compilation process encounters some trouble unless I remove labelsep=newline option for caption package. How do I fix this?

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 option labelsep=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{}

\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.