문제

아래에 나란히 그림을하는 매크로가 있습니다. 하위 플로트를 사용하므로 그림에 들어갑니다.

\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}

그런 다음 하위 플로트 사용에 동일한 플로트 (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}

다른 팁

하위 플로트 문서를 살펴 보겠습니다. "그림"환경에서 하위 플로트를 계산하는 매크로 호출이 있다고 확신합니다. "그림"환경 카운터를 "리스팅"으로 재정의 할 수 있습니다.

좋아, 이것은 잘못된 대답이지만 나는했다. 거의 이렇게 거기에 가십시오. 오른쪽에 캡션을 추가하지 못했습니다 \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}
}
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top