bicaption을 사용하는 방법과 lstlisting에 대한 이중 언어 이름을 정의하는 방법은 무엇입니까?

bicaption을 사용하는 방법과 lstlisting에 대한 이중 언어 이름을 정의하는 방법은 무엇입니까?

\bicaption논문에 코드에 대한 이중 언어 캡션을 작성해야 하는데 lstlisting.

lstlisting또한, 바이캡션의 이름을 Code로 변경하고 싶습니다 .

\renewcommand{\lstlistingname}{}을 사용하여 의 이름을 재정의 할 수 있다는 것을 알고 있지만 lstlisting두 언어로 변경해야 하는 경우 이름을 바꾸는 방법을 모르겠습니다.

% !TeX encoding = UTF-8
\documentclass{article}
\usepackage[UTF8]{ctex}

\RequirePackage{caption}
\RequirePackage[list=off]{bicaption}
\RequirePackage{subcaption}

\usepackage{listings}
\usepackage{bicaption}

\AtBeginDocument{\renewcommand*{\thelstlisting}{\thechapter-\arabic{lstlisting}}}

\begin{document}
    \begin{table}
        \centering
        \bicaption{表格测试}{Table Test}
        \begin{tabular}{|c|c|}
            \hline
            a&b\\
            \hline
            a&b\\
            \hline
            a&b\\
            \hline
        \end{tabular}
    \end{table}
    \lstset {
        language=C
    }
    \begin{figure}
        \centering
        \begin{lstlisting}[caption=Test example,captionpos=b]
            int foo() {
                return 0;
            }
        \end{lstlisting}
    \end{figure}
\end{document}

다음은 예입니다. 표와 마찬가지로 목록에 대해 두 개의 캡션을 갖고 싶습니다.

다음은 사용된 패키지 및 해당 버전 목록입니다.

 article.cls    2020/04/10 v1.4m Standard LaTeX document class
  size10.clo    2020/04/10 v1.4m Standard LaTeX file (size option)
    ctex.sty    2020/10/19 v2.5.5 Chinese adapter in LaTeX (CTEX)
   expl3.sty    2020-10-27 L3 programming layer (loader) 
l3backend-xetex.def    2020-09-24 L3 backend support: XeTeX
  xparse.sty    2020-10-27 L3 Experimental document command parser
l3keys2e.sty    2020-10-27 LaTeX2e option processing using LaTeX3 keys
ctexhook.sty    2020/10/19 v2.5.5 Document and package hooks (CTEX)
ctexpatch.sty    2020/10/19 v2.5.5 Patching commands (CTEX)
  fix-cm.sty    2015/01/14 v1.1t fixes to LaTeX
  ts1enc.def    2001/06/05 v3.0e (jk/car/fm) Standard LaTeX file
everysel.sty    2011/10/28 v1.2 EverySelectfont Package (MS)
ctexopts.cfg    2020/10/19 v2.5.5 Option configuration file (CTEX)
ctex-engine-xetex.def    2020/10/19 v2.5.5 XeLaTeX adapter (CTEX)
   xeCJK.sty    2020/10/19 v3.8.6 Typesetting CJK scripts with XeLaTeX
xtemplate.sty    2020-10-27 L3 Experimental prototype document functions
fontspec.sty    2020/02/21 v2.7i Font selection for XeLaTeX and LuaLaTeX
fontspec-xetex.sty    2020/02/21 v2.7i Font selection for XeLaTeX and LuaLaTeX
 fontenc.sty
fontspec.cfg
   xeCJK.cfg    2020/10/19 v3.8.6 Configuration file for xeCJK package
zhnumber.sty    2020/05/01 v2.8 Typesetting numbers with Chinese glyphs
zhnumber-utf8.cfg    2020/05/01 v2.8 Chinese numerals with UTF8 encoding
ctex-scheme-chinese.def    2020/10/19 v2.5.5 Chinese scheme for generic (CTEX)
ctex-name-utf8.cfg    2020/10/19 v2.5.5 Caption with encoding UTF-8 (CTEX)
indentfirst.sty    1995/11/23 v1.03 Indent first paragraph (DPC)
ctex-c5size.clo    2020/10/19 v2.5.5 c5size option (CTEX)
ctex-fontset-windows.def    2020/10/19 v2.5.5 Windows fonts definition (CTEX)
    ctex.cfg    2020/10/19 v2.5.5 Configuration file (CTEX)
 caption.sty    2020/10/26 v3.5g Customizing captions (AR)
caption3.sty    2020/10/21 v2.2e caption3 kernel (AR)
  keyval.sty    2014/10/28 v1.15 key=value parser (DPC)
bicaption.sty    2020/10/25 v1.3 Bilingual Captions (AR)
subcaption.sty    2020/10/07 v1.3j Sub-captions (AR)
listings.sty    2020/03/24 1.8d (Carsten Heinz)
 lstmisc.sty    2020/03/24 1.8d (Carsten Heinz)
listings.cfg    2020/03/24 1.8d listings configuration
xeCJK-listings.sty    2020/10/19 v3.8.6 xeCJK patch file for listings
  xpatch.sty    2020/03/25 v0.3a Extending etoolbox patching commands
etoolbox.sty    2020/10/05 v2.5k e-TeX tools for LaTeX (JAW)
lstlang1.sty    2020/03/24 1.8d listings language file
 lstmisc.sty    2020/03/24 1.8d (Carsten Heinz)

답변1

용법:

  • 새로운 listings옵션bicaption=<caption text>
  • 의 바이캡션 이름이 다음 lstlisting에 저장되어 있습니다.\lstlistingnameBi
\documentclass{article}
\usepackage{listings}
\usepackage{bicaption}
\usepackage{xpatch}

\makeatletter

% define new option "bicaption"
\lst@Key{bicaption}\relax{\lstKV@OptArg[{#1}]{#1}%
  {\def\lst@bicaption{##2}\def\lst@@bicaption{##1}}}
% init option
\lst@AddToHookExe{TextStyle}
  {\let\lst@bicaption\@empty \let\lst@@bicaption\@empty}

% new caption name
\def\lstlistingnameBi{Listing} % the name "Listing" in second language
\def\fnum@lstlisting@bi{%
  {\lstlistingnamestyle\lstlistingnameBi
  \ifx\lst@@caption\@empty\else~\thelstlisting\fi}}

% patch (the "caption" patched) \lst@MakeCaption to insert bicaption
\AtBeginDocument{
  \xpatchcmd\caption@ORI@lst@MakeCaption
    {\lst@makecaption\fnum@lstlisting{\ignorespaces \lst@caption}}
    {\lst@makecaption\fnum@lstlisting{\ignorespaces \lst@caption}%
     \ifx\lst@bicaption\@empty
     \else
       \lst@makecaption\fnum@lstlisting@bi{\ignorespaces \lst@bicaption}%
     \fi}
    {}{\fail}
}
\makeatother

\begin{document}

\renewcommand{\lstlistingnameBi}{Listing Bi Cap}
\begin{lstlisting}[
  basicstyle=\ttfamily,captionpos=b,language=C,gobble=2,
  caption=first caption, bicaption=second caption
]
  int foo() {
      return 0;
  }
\end{lstlisting}
\end{document}

여기에 이미지 설명을 입력하세요

관련 정보