在标题文本左侧绘制垂直线

在标题文本左侧绘制垂直线

您知道如何在标题文本之前、图形标签之后画一条垂直线,如下例所示吗? 在此处输入图片描述

垂直规则高度必须与标题文本框的高度相同。

我正在使用带有标题包的 scrbook。

非常感谢

答案1

以下示例定义了一种新的标题格式HangRedLine。格式的起点是标题格式的定义hang。它将完整的标题放在一个框中,并用红色规则覆盖它,该规则延伸到框的高度和深度。

\documentclass{scrbook}
\usepackage{tgpagella}% TeX Gyre Palladio (TeX Gyre's Palatino version)
\usepackage{caption}
\usepackage{xcolor}

\definecolor{CaptionBlue}{HTML}{005090}
\newcommand*{\RedCaptionLine}{%
  \leavevmode
  \llap{\color{red}\vline width 1pt\relax\,}%
}

\makeatletter

\newcommand*{\CaptionVLineWidth}{1pt}
\newcommand*{\CaptionVLineSep}{.2em}

\newcommand*{\CaptionVLine}{%
  \noindent
  \kern\dimexpr-\CaptionVLineSep-\CaptionVLineWidth\relax
  \textcolor{red}{\vline width\CaptionVLineWidth}%
  \kern\CaptionVLineSep\relax
}

\DeclareCaptionFormat{HangRedLine}[%
  #1#2\CaptionVLine#3\par % Single line captions
]{% Multi-line captions
  \caption@ifin@list\caption@lsepcrlist\caption@lsepname{%
    \caption@Error{%
      The option `labelsep=\caption@lsepname' does not work\MessageBreak
      with `format=hang'}
  }{%
    \sbox0{%
      \parbox[t]{\linewidth}{%
      \@hangfrom{#1#2}%
      \advance\caption@parindent\hangindent
      \advance\caption@hangindent\hangindent
      \xdef\CaptionHangIndent{\the\hangindent}%
      \caption@@par#3\par
      }%
    }%
    \noindent
    \kern\CaptionHangIndent\relax
    \CaptionVLine
    \kern-\CaptionHangIndent\relax
    \usebox0%
  }%
}
\makeatother

\captionsetup{
  labelsep=quad,
  labelfont={color=CaptionBlue},
  format=HangRedLine,
}

\begin{document}
\stepcounter{chapter}
\stepcounter{chapter}
\stepcounter{figure}

\begin{figure}
\caption{Illustration of the induced angle of attack
  and the induced drag caused by the downwash velocity $w$}
\caption{Short caption}
\end{figure}
\end{document}

结果


带有子图:

\documentclass{scrbook}
\usepackage{tgpagella}% TeX Gyre Palladio (TeX Gyre's Palatino version)
\usepackage{caption}
\usepackage{subcaption}
\usepackage{xcolor}

\definecolor{CaptionBlue}{HTML}{005090}
\newcommand*{\RedCaptionLine}{%
  \leavevmode
  \llap{\color{red}\vline width 1pt\relax\,}%
}

\makeatletter

\newcommand*{\CaptionVLineWidth}{1pt}
\newcommand*{\CaptionVLineSep}{.2em}

\newcommand*{\CaptionVLine}{%
  \noindent
  \kern\dimexpr-\CaptionVLineSep-\CaptionVLineWidth\relax
  \textcolor{red}{\vline width\CaptionVLineWidth}%
  \kern\CaptionVLineSep\relax
}

\DeclareCaptionFormat{HangRedLine}[%
  % Single line captions
  #1%
  \sbox0{#3}%
  \ifdim\wd0>0pt %
    #2\CaptionVLine#3%
  \fi
  \par
]{% Multi-line captions
  \caption@ifin@list\caption@lsepcrlist\caption@lsepname{%
    \caption@Error{%
      The option `labelsep=\caption@lsepname' does not work\MessageBreak
      with `format=hang'}
  }{%
    \sbox0{%
      \parbox[t]{\linewidth}{%
      \@hangfrom{#1#2}%
      \advance\caption@parindent\hangindent
      \advance\caption@hangindent\hangindent
      \xdef\CaptionHangIndent{\the\hangindent}%
      \caption@@par#3\par
      }%
    }%
    \noindent
    \kern\CaptionHangIndent\relax
    \CaptionVLine
    \kern-\CaptionHangIndent\relax
    \usebox0%
  }%
}
\makeatother


\captionsetup{
  labelsep=quad,
  labelfont={color=CaptionBlue},
  format=HangRedLine,
}
\captionsetup[sub]{
  labelsep=quad,
}

\begin{document}
\stepcounter{chapter}
\stepcounter{chapter}
\stepcounter{figure}

\begin{figure}
\begin{minipage}[b]{.5\linewidth}
  \centering
  \subcaption{A subfigure}
\end{minipage}%
\begin{minipage}[b]{.5\linewidth}
  \centering
  \subcaption{}
\end{minipage}
\caption{Illustration of the induced angle of attack
  and the induced drag caused by the downwash velocity $w$}
\caption{Short caption}
\end{figure}
\end{document}

带子图的结果

相关内容