[Tex/LaTex] Text-Align inside Caption

captionshorizontal alignment

I've some problem with formatting my figure captions form my thesis.
First i'd like to describe my final result.

  • Caption above: align left
  • Caption below – first row (source): align right
  • Caption below – rest: align left

Final result

Unfortunately
– Caption above: in the center
– Caption below: align right

I've tried all different kind of aligning-methods (\raggedleft, \begin{flushleft})

Thats what my code looks like

\documentclass[12pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{ragged2e}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}


\usepackage{graphicx}
\usepackage{caption}

\makeatletter
  \AtBeginDocument{%
    \def\Ginclude@graphics#1{%
      \begingroup\fboxsep=-\fboxrule
      \fbox{\rule{\@ifundefined{Gin@@ewidth}{150pt}{\Gin@@ewidth}}{0pt}%
      \rule{0pt}{\@ifundefined{Gin@@eheight}{100pt}{\Gin@@eheight}}}\endgroup}}
\makeatother

% Begin Document
\begin{document}

% Begin Figure
\begin{figure}[ht!]
    \centering
    \caption{Figure 1 - Title}
    \includegraphics[width=0.6\textwidth]{demo}
    \captionsetup{width=0.6\textwidth}
    \caption*{Source: Source1\ \\Captiontex Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt \label{fig:3}}
    \label{overflow}
\end{figure}


\end{document}

Best Answer

Supposedly your images may have different widths. As such, you'll be forced to adjust the width manually using \captionsetup{width=X} for every figure.

enter image description here

\documentclass{report}
\usepackage{ragged2e,graphicx}
\usepackage[margin=2cm]{geometry}

\usepackage{caption}
\captionsetup[figure]{%
  justification   = RaggedRight,% Or justified
  singlelinecheck = off}

% \imagesource{<source>}{<desc>}
\newcommand{\imagesource}[2]{%
  \par\vspace{\abovecaptionskip}%
  \parbox{\captionwidth}{\raggedleft Source: #1 \par
    \noindent\justifying #2
  }%
}

\begin{document}

\begin{figure}
  \centering\captionsetup{width=0.6\linewidth}
  \caption{Title}
  \includegraphics[width=0.6\linewidth, height=150pt]{example-image}
  \imagesource{Source1}{Captiontex Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt}
\end{figure}

\end{document}

The use of singlelinecheck=off works to initiate the appropriate justification when the caption fits on a single line. Also, I've defined \imagesource{<source>}{<desc>} which sets the image source using some pre-specified layout (as in your example). It's best to define macros for such things, as it promotes consistency.