2

I have some figures in my document aligned left in the margin and some figures in the body. When I want to put captions beneath them, there are some difficulties.

I tried to define a floatsetup to align the caption under the figure also left aligned with the marginpar. However if I do this the figure moves even further to the left. And also the figures who are aligned in the text body are affected (want to keep their caption in the body).

So can someone tell me:

  • How to align the caption text in the left marginpar, keeping the figure also aligned in the margin par
  • Define a separate floatsetup for figures left aligned in the margin part and figures in the body part, however, use the figure environment for both types of figures.

See my MWE and some added images of the wrong situation, one can go back to the original situation by disabling the floatsetup[figure].

\documentclass{scrreprt}

\usepackage[
includemp,
            showframe,
            reversemp,
            paperwidth=20.1cm,
            paperheight=25.80cm,
            top=2.30cm,
            bottom=3.4cm,
            inner=2.7cm,
            outer=2.7cm,
            marginparwidth=1.6cm, % Fixed for now
            marginparsep=0.4cm
            ]{geometry}

\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{caption}   % Correctly placed anchors for hyperlinks
\usepackage{floatrow}               % Set up captions of floats
\usepackage{chngpage}              % to adjust the width      

\floatsetup[figure]{margins=hangleft}
\setcapindent{0pt}


\makeatletter          % to set the marginpar on the left side in showframe
\let\Gm@vrules@mpi\Gm@vrules@mpii
\makeatother

\begin{document}

\begin{figure}[h]                                         
\begin{adjustwidth}{-\dimexpr\marginparwidth+\marginparsep}{}
\noindent\includegraphics[height=6cm]{blackbox}
\caption{example for overfull hbox when aligning figure in leftmargin part 
 example for overfull hbox when aligning figure in leftmargin part example 
 for overfull hbox when aligning figure in leftmargin part example for 
 overfull hbox when aligning figure in leftmargin part example for overfull 
 hbox when aligning figure in leftmargin part example for overfull hbox 
 when aligning figure in leftmargin part}
\end{adjustwidth}
\end{figure}

\begin{figure}[h] 
\centering                                        
\includegraphics[height=6cm]{blackbox}
\caption{example for overfull hbox when aligning figure in leftmargin part 
example for overfull hbox when aligning figure in leftmargin part example 
for overfull hbox when aligning figure in leftmargin part example for 
overfull hbox when aligning figure in leftmargin part example for overfull 
hbox when aligning figure in leftmargin part example for overfull hbox when 
aligning figure in leftmargin part}
\end{figure}

\end{document}

enter image description here

enter image description here

1

Just nest the figure environment inside adjustwidth, not the contrary, and add \raggedright command before inserting the graphic file. Note that chngpage is obsolete, and should be replaced with changepage.

\documentclass{scrreprt}

\usepackage[
            includemp,
            showframe,verbose,
             reversemp,
            paperwidth=20.1cm,
            paperheight=25.80cm,
            top=2.30cm,
            bottom=3.4cm,%
            hmargin = 2.7cm,
            marginparwidth=1.6cm, % Fixed for now
            marginparsep=0.4cm
            ]{geometry}

\usepackage{lipsum}
\usepackage{graphicx}%[demo]
\usepackage{caption} % Correctly placed anchors for hyperlinks
\usepackage{floatrow} % Set up captions of floats
\usepackage{changepage} % to adjust the width

\floatsetup[figure]{margins=hangleft}
\setcapindent{0pt}

%
\makeatletter % to set the marginpar on the left side in showframe
\let\Gm@vrules@mpi\Gm@vrules@mpii
\makeatother
\newlength{\adjmargin}
\setlength{\adjmargin}{\dimexpr\marginparwidth+\marginparsep\relax}

\begin{document}

\begin{adjustwidth}{-\adjmargin}{}
  \begin{figure}[!htb]
    \raggedright\includegraphics[height=6cm]{Nightmare_Fussli}
    \caption{example for overfull hbox when aligning figure in leftmargin part
      example for overfull hbox when aligning figure in leftmargin part example
      for overfull hbox when aligning figure in leftmargin part example for
      overfull hbox when aligning figure in leftmargin part example for overfull
      hbox when aligning figure in leftmargin part example for overfull hbox
      when aligning figure in leftmargin part}
  \end{figure}
\end{adjustwidth}

\end{document} 

enter image description here

  • One small thing. This example I made to use it in the end for a figure using an 'tabular environment' to place two figure next to eachother. However if I do this I get an error. {File ended while scanning use of \caption@xdblarg} Any Idea? – SLeenders Aug 11 '17 at 8:19
  • Or is it more convenient to make a new question including a MWE? – SLeenders Aug 11 '17 at 8:38
  • @Sleenders: Could you explain shols be the captions in case of two (or more) figures? Also are they independent figures or subfigures? – Bernard Aug 11 '17 at 9:21
  • I posted a new question including the code – SLeenders Aug 11 '17 at 9:26
0

You can use different setup for figure environment with floatrow by setting values for widefigure and using figure* environment for special figures. Maybe this is a starting point for you:

\documentclass{scrreprt}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{geometry}
\geometry{%
  includemp            ,
  showframe            ,
  verbose              ,
  reversemp            ,
  paperwidth=20.1cm    ,
  paperheight=25.80cm  ,
  top=2.30cm           ,
  bottom=3.4cm         ,
  hmargin = 2.7cm      ,
  marginparwidth=1.6cm ,
  marginparsep=0.4cm
}

\usepackage{floatrow,graphicx}

\floatsetup[figure]{%
  heightadjust      = all            ,
  margins           = raggedright    ,
  captionskip       = 10pt           ,
  capposition       = bottom         ,
  objectset         = centering      ,
  capbesideposition = {right,bottom} ,
  valign            = t
}

\floatsetup[widefigure]{%
  margins        = hangleft        ,
  objectset      = raggedright     ,
  capbesidewidth = \marginparwidth ,
  captionskip    = 7pt             ,
  floatwidth     = \textwidth}

\usepackage{caption}

\captionsetup{%
  font      = footnotesize,
  labelfont = {sf,bf}}

\captionsetup[figure]{%
  format        = plain      ,
  justification = centerlast ,
  labelsep      = quad
}

\captionsetup[widefigure]{%
  width=\dimexpr\textwidth+\marginparsep+\marginparwidth}

\makeatletter % to set the marginpar on the left side in showframe
\let\Gm@vrules@mpi\Gm@vrules@mpii
\makeatother

\begin{document}

\begin{figure}[h]
  \ffigbox{%
    \includegraphics[width=0.8\textwidth,height=3cm]{example-image-1x1}%
  }{%
    \caption{example for overfull hbox when aligning figure in
      leftmargin part example for overfull hbox when aligning figure
      in leftmargin part example for overfull hbox when aligning
      figure in leftmargin part example for overfull hbox when
      aligning figure in leftmargin part example for overfull hbox
      when aligning figure in leftmargin part example for overfull
      hbox when aligning figure in leftmargin part}%
  }%
\end{figure}

\begin{figure*}[h]
  \includegraphics[width=\textwidth,height=3cm]{example-image-16x9}
  \caption{example for overfull hbox when aligning figure in
    leftmargin part example for overfull hbox when aligning figure in
    leftmargin part example for overfull hbox when aligning figure in
    leftmargin part example for overfull hbox when aligning figure in
    leftmargin part example for overfull hbox when aligning figure in
    leftmargin part example for overfull hbox when aligning figure in
    leftmargin part}%
\end{figure*}

\end{document}

enter image description here

  • Thanks! Also works, but for simplicity used the one below. – SLeenders Aug 11 '17 at 8:06

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.