LoginSignup
2
2

More than 1 year has passed since last update.

LaTeXを初めて使ってみた

Last updated at Posted at 2019-01-02

概要

初めてLaTeXを使って詰まったところを自分用にまとめてみた。

Hello World!

レポートを書くときはjsreport,本を書くときはjsbook
詳細→https://medemanabu.net/latex/documentclass/

環境によってjsarticleのところがujsarticle等になる。
jsarticleの方が余白が少ない。
参考→https://qiita.com/SUZUKI_Masaya/items/e1ae2eb42626dc6d9155

hello.tex
\documentclass[uplatex]{jsarticle}
\begin{document}
Hello World!
\end{document}
実行結果
Hello World!

コメントアウト

%でコメントアウト

%コメントアウトしています

タイトル、名前等

sample.tex
\documentclass[uplatex]{jsarticle}

% プリアンブル
\title{タイトル}
\author{山田 太郎 \and 山田 花子}
\date{2018/01/03}

\begin{document}
  % タイトルを出力
  \maketitle

  \section{}
  文章
\end{document}

実行結果
スクリーンショット 2019-01-03 4.47.04.png

箇条書き

番号付き箇条書き

\begin{itemize}
  \item item1
  \item item2
  \item item3
\end{itemize}
実行結果
・item1
・item2
・item3

番号付き箇条書き

\begin{enumerate}
  \item item1
  \item item2
  \item item3
\end{enumerate}
実行結果
1. item1
2. item2
3. item3

見出し付き箇条書き

\begin{description}
  \item[日程] 2018年1月3日
  \item[場所] 札幌駅
  \item[料金] 3,000円
\end{description}
実行結果
日程  2018年1月3日
場所  札幌駅
料金  3,000円

箇条書きや見出し直後の改行

以下のように~\\を入力するだけ。
~がスペース, \\が改行を表している。

\begin{description}
  \item[日程] ~\\2018年1月3日
  \item[場所] ~\\札幌駅
  \item[料金] ~\\3,000円
\end{description}
実行結果
日程
    2018年1月3日
集合場所
    札幌駅
参加費
    3,000円

ソースコード

Wordではソースコードを見やすく載せる方法が限られていたので
この機能はLaTeXを使って初めて感動した。

sample2.tex
\documentclass[uplatex]{jsarticle}
\usepackage{listings}%,ソースコードをLatexに挿入するためのパッケージ

%ソースコードの表示に関する設定
\lstset{
  basicstyle={\ttfamily},
  identifierstyle={\small},
  commentstyle={\smallitshape},
  keywordstyle={\small\bfseries},
  ndkeywordstyle={\small},
  stringstyle={\small\ttfamily},
  frame={tb},
  breaklines=true,
  columns=[l]{fullflexible},
  numbers=left,
  xrightmargin=0zw,
  xleftmargin=3zw,
  numberstyle={\scriptsize},
  stepnumber=1,
  numbersep=1zw,
  lineskip=-0.5ex
}

\begin{document}
HelloWorldのソースコードを,ソースコード\ref{hello}に示す。

%ここにソースコードを載せる
\begin{lstlisting}[caption=hello.c,label=hello]
#include <stdio.h>

int main() {
    printf("Hello World");
    return 0;
}
\end{lstlisting}
\end{document}

実行結果
スクリーンショット 2019-01-03 4.08.51.png

他にも色々なソースコードの書き方がある。
https://www.biwako.shiga-u.ac.jp/sensei/kumazawa/tex/listings.html

参考文献

https://medemanabu.net/latex/documentclass/
http://www.latex-cmd.com/struct/list.html#itemize
https://qiita.com/ta_b0_/items/2619d5927492edbb5b03
http://www.latex-cmd.com/struct/title.html
https://www.biwako.shiga-u.ac.jp/sensei/kumazawa/tex/listings.html
https://postd.cc/begin-latex-in-minutes/
http://www.robotics.hiroshima-u.ac.jp/exp/tex/platex.html#tex
https://texwiki.texjp.org/?LaTeX%E5%85%A5%E9%96%80

2
2
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
2
2