2
2

More than 5 years have passed since last update.

初めてのtexで使った図の挿入,数式,テーブルの使い方など(メモ)

Last updated at Posted at 2017-10-31

texの図,数式,画像,テーブルの書き方

とりあえずパッケージ指定

.tex

¥documentclass[a4j]{jsarticle}  % jsarticle が使えないときは jarticle に変更

¥usepackage[dvipdfmx]{graphicx}    % dvipdfmx を使って PDF ファイルを
                                % 作成するときは dvips を dvipdfm に変更

¥usepackage{subfigure}          % 複数の図を並べるときに使用

¥usepackage{amsmath}            % 複雑な数式が利用可能

¥usepackage{ascmac, fancybox}   % 枠囲みが利用可能(プログラム等の表示に便利)

¥usepackage{psfrag}             % 図に数式などを入れる際に使う

¥usepackage{./style}              % スタイルファイル(style.sty)(相対パスで指定可)
¥usepackage{verbatim}
¥usepackage{here}               %画像,tableを順番に表示させる[H]で指定
¥usepackage{framed}
¥usepackage{cases}
¥usepackage{url}

数式

¥setcounter{equation}{0}
¥begin{equation}
  h(k) = ¥sum^{M-1}_{m=0}¥sum^{N-1}_{n=0}¥delta(k,f(m,n))
¥end{equation}

複数(&&で囲むとそこを揃えてくれる)
¥begin{eqnarray}
  ¥sigma_{B} & = & ¥omega{1} ¥nonumber ¥¥
  P_{1}(z) & = & ¥frac{1}{M・N}¥sum^{z}_{i=0}h(i)
¥end{eqnarray}

修飾文字編
^{上付き文字}
_{下付き文字}
\overline{A}
\underline{A + B}
\sigma←こんな感じでギリシャ文字

$\sigma$で囲むと文章中に数式をかける

画像

¥begin{figure}[H]
  ¥centering
    ¥includegraphics[width=150mm]{./images/analog_to_digital1.png}
    ¥caption{:ディジタル画像}
    ¥label{fig:zu1}
¥end{figure}

2個並べる
 ¥begin{figure}[H]
 ¥begin{minipage}{0.5¥hsize}
  ¥begin{center}
   ¥includegraphics[width=60mm]{./images3-2/case1_t.eps}
¥¥(a) 分離超平面[Case 1]
  ¥end{center}
 ¥end{minipage}
 ¥begin{minipage}{0.5¥hsize}
  ¥begin{center}
   ¥includegraphics[width=60mm]{./images3-2/case2_t.eps}
¥¥(b) 分離超平面[Case 2]
  ¥end{center}
 ¥end{minipage}
 ¥caption{それぞれのケースの線形分離可能性}
  ¥label{fig:separating_hyperplane}
¥end{figure}

captionの初期化(図1から始める)
¥setcounter{figure}{0}

¥frac{分子}{分母}¥sum^{zまで}_{i=0から}h(i)
偏微分
\[
  \frac{\partial f}{\partial y},
  \frac{\partial^2 f}{\partial^2 y},
  \frac{\partial}{\partial x} \left(\frac{\partial z}{\partial y}\right)
\]

テーブル

¥begin{center}
¥begin{table}[H]
  ¥begin{tabular}{|p{4cm}|p{4cm}|p{4cm}|p{4cm}|} ¥hline
     & pタイル法 & モード法 & 判別分析法 ¥¥ ¥hline ¥hline
    閾値決定方法 & 手動 & 手動or自動 & 自動¥¥ ¥hline
    備考 & 対象物が画像の全体の何割を占めているかによってパラメータを変更する. & 画像の濃度ヒストグラムを作成し,濃度グラフの特徴点を判断して閾値を決定,明確なヒストグラムを持たない画像にはうまく閾値を決定することができない. &  画像の濃度値のヒストグラムを閾値$¥theta$で二つのクラスに分割した時に2クラス間の分離がもっとも良くなるように閾値を定める. ¥¥ ¥hline
  ¥end{tabular}
¥end{table}
¥end{center}

¥begin{table}[ht]
 ¥centering
 ¥caption{トレースモードにおけるシンボルの意味}
 ¥label{tab:trace}
 ¥begin{tabular}{l|l}  
  ¥hline
  シンボル & 状態                         ¥¥ 
  ¥hline
  Call     & 述語への適合の開始           ¥¥
  Exit     & 述語への適合が成功           ¥¥
  Redo     & バックトラックし,別解の探索 ¥¥
  Fail     & 述語への適合が失敗           ¥¥ 
  ¥hline
 ¥end{tabular}
¥end{table}

ソースの乗せ方

ちょいソースのせ
¥begin{quote}
 ¥begin{itembox}[l]{画像を左右反転させるプログラム(一部掲載)}
¥begin{verbatim}
内容
¥end{verbatim}
 ¥end{itembox}
¥end{quote}

説明なしで載せる
¥begin{screen}
    ¥begin{verbatim}
        %gcc sigchldtest.c -o sigchldtest
    ¥end{verbatim}
¥end{screen} 

がっつりソースのせ
¥subsection{プログラム}
¥begin{framed}
     ¥verbatiminput{./sources1-2/program.c}
¥end{framed}

enumerate

\begin{enumerate}
\renewcommand{\labelenumi}{\arabic{enumi}).}
\item aaa
\item bbb
   \begin{enumerate}
   \renewcommand{\labelenumii}{\Roman{enumii}).}
   \item aaaaaa
   \item bbbbbb
   \item cccccc
      \begin{enumerate}
      \renewcommand{\labelenumiii}{\alph{enumiii}).}
      \item aaaaaaaaaaaa
      \item bbbbbbbbbbbb
      \end{enumerate}
   \end{enumerate}
\item ccc
\end{enumerate}

もっといいソースの乗せ方

¥usepackage{listings}
\lstset{
  language=bash,
  linewidth=12.5cm,
  breaklines=true,
  basicstyle={\ttfamily\small},
  commentstyle={\footnotesize\itshape},
  keywordstyle={\footnotesize\bfseries},
  ndkeywordstyle={\footnotesize},
  stringstyle=\ttfamily,
  showstringspaces=false,
  columns=[l]{fullflexible},
  numbers=left,
  xleftmargin=-0.5cm,
  xrightmargin=0cm,
  numberstyle={\scriptsize},
  frame={shadowbox}
}

してから

\begin{minted}{c}
#include<stdio.h>
int main(void){
printf("Hello World!\n");
return 0;
}
\end{minted}

http://muscle-keisuke.hatenablog.com/entry/2016/02/11/195004
を参考にlistingを入れると画像が消えてしまったので,調べてみると
http://geektrainee.hatenablog.jp/entry/2013/11/26/231847
によると,
graphicxパッケージとcolorパッケージは衝突するらしい。つまり、どちらかしか使えないというのでcolorは未使用です.ちょっと見にくい残念

箇条書き

\begin{itemize}
 \setlength{\itemsep}{-5pt}
 \item 運動の第一法則とは,慣性の法則のことです.
 \item 運動の第二法則とは,運動方程式のことです.
 \item 運動の第三法則とは,作用反作用の法則のことです.
\end{itemize}

見出しつき箇条書き

\begin{description}
 \item[運動の第一法則]慣性の法則のことです.
 \item[運動の第二法則]運動方程式のことです.
 \item[運動の第三法則]作用反作用の法則のことです.
\end{description}

screen環境

¥begin{screen}
¥begin{verbatim}
%union {
型 フィールド名;
.....
}   
¥end{verbatim}
¥end{screen}

shadebox環境

¥begin{center}
¥begin{shadebox}
¥begin{verbatim}
内容
¥end{verbatim}
¥end{shadebox}
¥end{center}

error編

! File ended while scanning use of \@writefile.
が出たらauxファイルとかを消して再コンパイル,数式などのエラーが原因
あと,documentの前に全角文字が入ってるかもしれないから消そう

パッケージの追加の仕方

.texファイルと同じディレクトリにおいて\usepackege{package name}するか,以下を参考にしてTEXMFHOMEを変更
http://clngn.hatenablog.com/entry/20120206/1328537665

レポート用

¥setcounter{section}{0}
¥begin{center}
 {¥Large ¥bf タイトル}
¥end{center}
¥setcounter{section}{0}

%目的
¥section{目的}


%原理
¥section{原理}

%実験
¥section{実験}


%結果
¥section{結果}


%考察
¥section{考察}


%課題
¥section{課題}

特殊文字

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