¿Cómo utilizar bicaption y cómo definir nombres bilingües para listar?

¿Cómo utilizar bicaption y cómo definir nombres bilingües para listar?

Necesito escribir subtítulos bilingües para códigos en un documento, pero no sé cómo \bicaptionusarlos lstlisting.

Además, quiero cambiar el nombre de lstlistingCódigo en el bitítulo.

Sé que puedo usar \renewcommand{\lstlistingname}{}para redefinir el nombre de lstlisting, pero no sé cómo cambiarle el nombre si necesito cambiarlo en dos idiomas.

% !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}

Aquí hay un ejemplo: quiero tener dos títulos para la lista al igual que la tabla.

A continuación se muestra la lista de paquetes usados ​​y sus versiones.

 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)

Respuesta1

Uso:

  • nueva listingsopciónbicaption=<caption text>
  • El nombre del bicaption lstlistingse almacena en\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}

ingrese la descripción de la imagen aquí

información relacionada