5

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}
4
  • Is the left-alignment of the caption/source related to the width of the image, or the width of the text block?
    – Werner
    Nov 24 '14 at 21:38
  • everything ist related to the width of the image Nov 24 '14 at 21:54
  • Then you'll have to be sure to set the \captionsetup{width=X} key with every figure environment.
    – Werner
    Nov 24 '14 at 22:03
  • it's better not to consider everything a caption -- you will most likely want to use only one of these as a link point. choose that one, and mark it as the caption, with a label if it's to be linked. then treat the rest as text within the figure environment. nobody ever said that only the graphic was to be considered a figure! and certainly, the source is most unlikely to be considered a caption. Nov 24 '14 at 22:31
3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.