![目次で使用する lstset のカスタム キャプション](https://rvso.com/image/298809/%E7%9B%AE%E6%AC%A1%E3%81%A7%E4%BD%BF%E7%94%A8%E3%81%99%E3%82%8B%20lstset%20%E3%81%AE%E3%82%AB%E3%82%B9%E3%82%BF%E3%83%A0%20%E3%82%AD%E3%83%A3%E3%83%97%E3%82%B7%E3%83%A7%E3%83%B3%20.png)
図のキャプション機能(2 つのキャプションを持つことができます。1 つは目次用、もう 1 つは図の下/上のキャプション用)をカスタム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}