목차에 사용할 lstset의 사용자 정의 캡션

목차에 사용할 lstset의 사용자 정의 캡션

내 사용자 정의 환경에서 그림 캡션 기능(두 개의 캡션(목차용 캡션과 그림 아래/위 캡션용 캡션)을 사용할 수 있음)을 사용하고 싶습니다 filecode. MWE:

\documentclass[11pt,a4paper]{article}
\usepackage{listings}
\usepackage{color}
\usepackage{courier}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\definecolor{darkblue}{rgb}{0.0,0.0,0.6}
\definecolor{cyan}{rgb}{0.0,0.6,0.6}

\lstset{frame=tb,
  language=C++,
  showstringspaces=false,
  columns=fullflexible,
  basicstyle={\scriptsize\ttfamily},
  numbers=left,
  numbersep=4pt,
  numberstyle=\scriptsize\color{gray},
  keywordstyle=\color{blue},
  commentstyle=\color{gray}\upshape,
  stringstyle=\color{mauve},
  moredelim=[s][\color{gray}]{@}{\ },
  breaklines=true,
  breakatwhitespace=true,
  tabsize=2
}

\newenvironment{filecode}[1][]
  {\vspace{1ex} \minipage[0.5\textheight]{\linewidth}% \begin{filecode}[#1]
   \lstset{basicstyle=\fontfamily{pcr}\footnotesize,#1}}
  {\endminipage \vspace{1em}}% \end{filecode}

\begin{document}

\begin{filecode}[label=lst:code,caption=Very long and frustrating caption that noone want to see before this page]
  \lstinputlisting{main.cpp}
\end{filecode}

\end{document}

답변1

사용

caption={[Short caption]Very long and frustrating caption that noone want to see before this page}

전체 코드:

\documentclass[11pt,a4paper]{article}
\usepackage{listings}
\usepackage{color}
\usepackage{courier}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\definecolor{darkblue}{rgb}{0.0,0.0,0.6}
\definecolor{cyan}{rgb}{0.0,0.6,0.6}

\lstset{frame=tb,
  language=C++,
  showstringspaces=false,
  columns=fullflexible,
  basicstyle={\scriptsize\ttfamily},
  numbers=left,
  numbersep=4pt,
  numberstyle=\scriptsize\color{gray},
  keywordstyle=\color{blue},
  commentstyle=\color{gray}\upshape,
  stringstyle=\color{mauve},
  moredelim=[s][\color{gray}]{@}{\ },
  breaklines=true,
  breakatwhitespace=true,
  tabsize=2
}

\newenvironment{filecode}[1][]
  {\vspace{1ex} \minipage[0.5\textheight]{\linewidth}% \begin{filecode}[#1]
   \lstset{basicstyle=\fontfamily{pcr}\footnotesize,#1}}
  {\endminipage \vspace{1em}}% \end{filecode}

\begin{document}
\lstlistoflistings
\begin{filecode}[label=lst:code,caption={[Short caption]Very long and frustrating caption that noone want to see before this page}]
  \lstinputlisting{main.cpp}
\end{filecode}

\end{document}

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

관련 정보