はじめに
コードとかをLaTeXに載せるとき,どうしていますか?
キャプチャして画像ぺた?
いいえ,listingsパッケージを使いましょう
これを使えば,hello.cというコードLaTex中に挿入できるね.
\usepackage[listings]
\lstset{
... % ここは自分で参考から調べてね.(他人任せ)
}
\begin{document}
コード\ref{hello}にHelloWorldのCコードを示す.
\lstinputlisting[caption=HelloWorldのCコード,lavel=hello]{hello.c}
\end{document}
名前や目次の変更
一番言いたかったことはこの後で,図であれば,図1だったり,図2.3だったりするよね.表も然り.
しかし,このままでは表示されるコードの名前のところがListing1になるので,これをコード1にする.
(コード: HelloWorldのCコード)ってしたい.
% the caption label for it.
\renewcommand{\figurename}{図}
\renewcommand{\tablename}{表}
\renewcommand{\lstlistingname}{コード}
% the header name for the list of it.
\renewcommand{\listfigurename}{図目次}
\renewcommand{\listtablename}{表目次}
\renewcommand{\lstlistlistingname}{コード目次}
\begin{document}
\tableofcontents % 目次
\listoffigures % 図の目次
\listoftables % 表の目次
\lstlistoflistings % コードの目次
\end{document}
これを使えば,図をfigureにしてみたり,英語の論文にする時に便利そうね☆
個人的にListingsはコードかなぁとか思ってみたり.
あと,lstlistlistingnameってlstのlistingnameのためのlistってなんだよw
参考資料
listings.styパッケージ
listings package のディレクトリ
listings package の pdf