使用左边距对齐字幕

使用左边距对齐字幕

我的文档中有一些图在页边空白处左对齐,还有一些图在正文中。当我想在它们下面添加标题时,遇到了一些困难。

我尝试定义一个floatsetup对齐图形下方的标题,并将其与marginpar左对齐。但是,如果我这样做,图形会进一步向左移动。而且,文本主体中对齐的图形也会受到影响(希望将其标题保留在主体中)。

有人可以告诉我吗:

  • 如何将标题文本左对齐marginpar,同时保持图形与边距对齐
  • floatsetup为边距部分左对齐的图形和正文部分中的图形定义一个单独的图形环境,但是,对这两种类型的图形都使用图形环境。

查看我的 MWE 和一些错误情况的添加的图像,可以通过禁用返回到原始情况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}

在此处输入图片描述

在此处输入图片描述

答案1

只需将图形环境嵌套在 内adjustwidth,而不是相反,并\raggedright在插入图形文件之前添加命令。请注意chngpage已过时,应替换为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} 

在此处输入图片描述

答案2

您可以通过设置值和使用环境来为特殊图形使用不同的figure环境设置。也许这是您的起点:floatrowwidefigurefigure*

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

在此处输入图片描述

相关内容