ラテックス:リストsubfloats使用リストカウンタを作る方法を、TOCなど
質問
私は以下、サイド・バイ・サイドの数字を行うマクロを持っています。それはsubfloatsを使用し、それが図になっています。
\newcommand{\listbylist}[6][showlines=true]{
\begin{figure}
\subfloat[ ]{
\lstinputlisting[showlines=true,#1]{#2}
\label{#4:A}
}
\hfill{}
\subfloat[ ]{
% by setting the frame to leftline, we avoid a box into oblivion
% turn off numbers
\lstinputlisting[showlines=true,frame=leftline,#1,numbers=none]{#3}
\label{#4:B}
}
\hfill{}
\caption[#5]{#6}
\label{#4}
\end{figure}
}
残念ながら、これは図のカウンターではなく、リストのものを使用しています。また、
?これを修正する方法はありますなど、内容の間違ったテーブルに表示され、キャプションに代わり「一覧」の言葉「図」を使用し、それへの参照私はどこかに単語「リスト」を追加するように、簡単な方法を好むだろう...
解決
の代わりに使用しての、lstlistingsのフロートを内蔵カスタムフロートでそれらをラップします:
\begin{mylisting}
\begin{lstlisting}
int x = 1;
\end{lstlisting}
\end{mylisting}
次にsubfloatの使用のために同一のフロート(mylisting)を使用します。
\newcommand{\listbylist}[6][showlines=true]{
\begin{mylisting}
\subfloat[ ]{
...
}
\hfill{}
\subfloat[ ]{
...
}
\hfill{}
\caption[#5]{#6}
\label{#4}
\end{mylisting}
}
これは前文で設定するすべての必要があります。
\newfloat{mylisting}{tbphH}{lopbl}[chapter]
\floatname{mylisting}{Listing}
\newsubfloat{mylisting}
\newcommand{\listofmylistings}{\listof{mylisting}{List of Listings}}
% if you use the hyperref package
\providecommand*\theHmylisting{\themylisting}
他のヒント
あなたはsubfloatのドキュメントを見てしたい場合があります。私は、「図」の環境でsubfloat数を作るマクロ呼び出しがあると確信しています。それはまったく理にかなっている場合は、
- あなたは「リスト」に環境カウンタ「フィギュア」を試してみて、再定義することができます。 OK、これは間違った答えですが、私は、のほとんどのこのようにそこ手に入れました。それだけで右\listof
にキャプションを追加できませんでした。
ほとんどあり。それ おそらくより良い行われますが、こののほとんどの作品することができます。すべてのことは、それはキャプションがないの.locファイル、.lolファイルに表示されるようにすることです残っています。私は、この答えを修正し、それについて質問をします。
基本的に、これは単に「数字」カウンターをバックアップし、「リスト」店頭でコピーします。フィギュアの後、それはそれらをバック置きます。
% Need a counter to save the value to
\newcounter{pbsavefigurecounter}
\newcommand{\listbylist}[6][showlines=true]{
{% scope
% Change ``Figure'' to ``Listing''
\renewcommand{\figurename}{Listing}
% save the figure counter
\setcounter{pbsavefigurecounter}{\value{figure}}
% copy the listings counter to the figure counter
\setcounter{figure}{\value{lstlisting}}
\begin{figure}
\subfloat[ ]{
\lstinputlisting[nolol,showlines=true,#1]{#2}
\label{#4:A}
}
\hfill{}
\subfloat[ ]{
% by setting the frame to leftline, we avoid a box into oblivion
% turn off numbers
\lstinputlisting[nolol,showlines=true,frame=leftline,#1,numbers=none]{#3}
\label{#4:B}
}
\hfill{}
% \float@caption{lol}[#5]{#6}
\label{#4}
\end{figure}
% Update the listings counter
\setcounter{lstlisting}{\value{figure}}
% Restore the figure counter
\setcounter{figure}{\value{pbsavefigurecounter}}
% Change ``Listing'' back to ``Figure''
\renewcommand{\figurename}{Figure}
}
}
所属していません StackOverflow