如何將清單和圖表合併為一個圖表?

如何將清單和圖表合併為一個圖表?

我正在使用 package 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}

相關內容