如何将列表和图形合并为一个图形?

如何将列表和图形合并为一个图形?

我正在使用包listings,我想将 alisting和 a组合figure成一个浮点数。作为示例,我使用listings如下方法:

\begin{lstlisting}[language=XML,float=h,label=lst:transition_selector_example, 
  basicstyle=\footnotesize\ttfamily,tabsize=2,
  caption={Example SCXML document used to illustrate transition selection optimization strategies}]
<scxml>
    <state id="A">
        <transition target="B" event="e1" id="transition1"/>
        <transition target="B" event="e2" id="transition2"/>
        <transition target="B" event="e2" id="transition3"/>
    </state>
    <state id="B">
        <transition target="A" event="e3" id="transition4"/>
    </state>
</scxml>
\end{lstlisting}

后来,我得到了一个里面有的图\includegraphics,如下所示:

\begin{figure}[p]
\centering
\includegraphics[width=1.00\textwidth]{chapters/3/figures/firefox-transitionSelector}
\caption{Results of Transition Selection optimization strategy in Firefox}
\label{fig:firefox-transitionSelector}
\end{figure}

我想让列表成为该图的一部分,以便它共享该图的参考编号,并作为单个组合图形实体在页面中布局。

我将非常感激任何人能提供的关于如何做到这一点的指导。

答案1

listings并且\includegraphics基本上每个都可以包含在任何地方。下面将它们一个放在另一个之上,如果您将列表放入一个宽度允许图形放在一边的迷你页面中,也可以并排布局。

\begin{figure}[p]
\centering
\includegraphics[width=1.00\textwidth]{chapters/3/figures/firefox-transitionSelector}

\begin{lstlisting}[language=XML,float=h,label=lst:transition_selector_example,basicstyle=\footnotesize\ttfamily,tabsize=2,caption={Example SCXML document used to illustrate transition selection optimization strategies}]
<scxml>
    <state id="A">
        <transition target="B" event="e1" id="transition1"/>
        <transition target="B" event="e2" id="transition2"/>
        <transition target="B" event="e2" id="transition3"/>
    </state>
    <state id="B">
        <transition target="A" event="e3" id="transition4"/>
    </state>
</scxml>
\end{lstlisting}

\caption{Results of Transition Selection optimization strategy in Firefox}
\label{fig:firefox-transitionSelector}
\end{figure}

答案2

补充一下戴维的回答(如果你想要“子字幕”):

在此处输入图片描述

\documentclass{article}

\usepackage{subcaption}
\usepackage{listings}
\usepackage[demo]{graphicx}

\begin{document}

\begin{figure}
    \begin{subfigure}[b]{\textwidth}
        \begin{lstlisting}[%
            language=XML,%
            label=lst:transition_selector_example,%
            basicstyle=\footnotesize\ttfamily,%
            tabsize=2
        ]
        <scxml>
            <state id="A">
                <transition target="B" event="e1" id="transition1"/>
                <transition target="B" event="e2" id="transition2"/>
                <transition target="B" event="e2" id="transition3"/>
            </state>
            <state id="B">
                <transition target="A" event="e3" id="transition4"/>
            </state>
        </scxml>
        \end{lstlisting}
        \subcaption{Example SCXML document used to illustrate\ldots}
    \end{subfigure}

    \vspace{2em}
    \begin{subfigure}[b]{\textwidth}
    \includegraphics[width=1.00\textwidth]{chapters/3/figures/firefox-transitionSelector}
    \subcaption{A screenshot (??)}
    \end{subfigure}
    \label{fig:firefox-transitionSelector}
    \caption{Results of Transition Selection optimization strategy in Firefox}
\end{figure}

\end{document}

相关内容