让文字环绕标题中的字母

让文字环绕标题中的字母

我想为我的图表创建标题样式。目前,我尝试使用caption包。标题应排版在边距段落中。标题应如下所示:带有文字的侧边标题 (两行灰色矩形框内以粗体显示“图 x”,文字包装大约)。

到目前为止,我尝试使用 lettrine 包来创建它,它在标题之外确实产生了良好的效果(图像就是这样完成的)。

该代码确实有效(但它不是真正的标题......):

\usepackage{lettrine}
\usepackage{tikz}
...
\marginpar{
    \lettrine
        [lhang=0, lines=2, findent=.5em, nindent=0em ]
        {\normalsize\tikz{
            \node[anchor=west, inner sep=2mm, fill=Grey, font=\bfseries, text=red]
                {Fig. 1};
        }}{}%
    text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text 
}

但是,当用作标题样式时,它不起作用!为什么?

\usepackage{caption}
\usepackage{xparse}
\usepackage{lettrine}
\usepackage{tikz}
\DeclareCaptionLabelFormat{myLabelStyle}{%
    \lettrine
        [lhang=0, lines=2, findent=.5em, nindent=0em ]
        {\normalsize\tikz{
            \node[anchor=west, inner sep=2mm, fill=Grey, font=\bfseries, text=red]
                {#1 #2}; % #1 is the float name (here "Fig.") and #2 is the float number
    }}{}%
}

\DeclareCaptionStyle{myReportCaptionStyle}{labelsep=none, labelformat=myLabelStyle}
\captionsetup*[figure]{style=myReportCaptionStyle}
\DeclareDocumentCommand{\sideCaptionOf}{m m}{\marginpar{\captionof{#1}{#2}}}

梅威瑟:

\documentclass{article}
\usepackage[
    a4paper,
    twoside,
    top=20mm,
    bottom=20mm,
    inner=20mm,
    outer=20mm,
    includemp,
    marginparwidth=52mm,
    marginparsep=8mm,
    headsep=10mm,
    footskip=8mm,
    headheight=12.2pt,
]{geometry}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{lettrine}
\usepackage{caption}
\usepackage{tikz}
\usepackage{xparse}

\DeclareCaptionLabelFormat{myLabelStyle}{%
    \lettrine
        [lhang=0, lines=2, findent=.5em, nindent=0em ]
        {\normalsize\tikz{
            \node[anchor=west, inner sep=2mm, fill=Grey, font=\bfseries, text=red]
                {#1 #2};
    }}{}%
}

\DeclareCaptionStyle{myReportCaptionStyle}{labelsep=none, labelformat=myLabelStyle}
\captionsetup*[figure]{style=myReportCaptionStyle}
\DeclareDocumentCommand{\sideCaptionOf}{m m}{\marginpar{\captionof{#1}{#2}}}


\begin{document}
% Working
\newpage
\marginpar{
    \lettrine[lhang=0, lines=2, findent=.5em, nindent=0em ]{\normalsize\tikz{\node[anchor=west, inner sep=2mm, fill=Grey, font=\bfseries, text=red] {Fig. 1};}}{}%
    text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text 
}
\begin{figure}[ht!]
    \rule{\linewidth}{6cm}
\end{figure}

% Not working
\newpage
\begin{figure}
    \rule{\linewidth}{6cm}
    \sideCaptionOf{figure}{My caption text}
\end{figure}
\end{document}

最后说明:据我了解,问题在于无法在标题中使用 parshape。但为什么呢?那么如何产生相同的效果呢?

相关内容