3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

LaTeXでコードを載せるときとか目次の作り方とか.図をfigureや表をtableに変更する方法も

Last updated at Posted at 2018-01-20

はじめに

コードとかを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

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?