LaTeXのTips - arosh/arosh.github.com GitHub Wiki
- 。 → .
- 自立分散 → 自律分散
文中で± (\textpm
) を表示するのに使った
tabular
の罫線をかっこ良くする。\toprule
,\midrule
,\cmidrule{3-4}
,\bottomrule
などが使える
\includegraphics
を使うために必要。テンプレ入り。
□とか△とかの一部の記号を入力するために必要
URLをいい感じに表示する。
verbatim
を中央揃えにするためにBVerbatim
というのが使える。
\begin{figure}
\centering
% \small
\begin{BVerbatim}
hoge~~~
\end{BVerbatim}
% \caption{}
% \label{}
\end{figure}
\begin{center}
\begin{BVerbatim}
hoge~~~
\end{BVerbatim}
\end{center}
長い文をBVerbatim環境で囲んでcenter環境で囲むと,上の余白がおかしなことになるので,そういう場合は普通に\begin{Verbatim}
すると良い.
『図をその場に出したい』を参照。
\bm{x}
でベクトルの太字が出る
『図表だけ1段組』を参照.
<
>
|
を入力するのに必要。
英文の本文のフォントがComputer Modernならlmodernパッケージも利用したほうがよい。
LaTeX の「アレなデフォルト」 傾向と対策 - Qiita
\begin{tabularx}{\columnwidth}{XXr}
hoge & fuga & 33.4
\end{tabularx}
のようにすると,幅が良さげな感じになる
\usepackage[group-separator={,}]{siunitx}
してから\num{12345}
すると12,345のようになる.
4桁の場合は1,234にならず1234になるが,これは英語のルール上validらしい.
Excelは指数表示を1.23E-4
のように出力するが,これを書くときも\SI{1.23E-4}{}
と書いておけば\times
を使った表記にしてくれる.
数式を書くための有名なパッケージ.詳しくはTeX Wikiのサンプルを参照.
align
環境の前に空行を入れると空白が目立ちすぎるので,空白を入れてはならないという罠が存在する.
数式を左揃えにするときには fleqn
というオプションを指定する。
実数とかを表すときの \mathbb{R}
に必要
\date{\empty}
\pagestyle{empty}
$tf\mathchar`-idf$
そもそも$mathrm{TF-IDF}$
とするべきでは?という疑問はある。
\verb#ptr#
と\texttt{ptr}
のどっちが良いのだろう…
\newcommand{\var}
するべきかもしれない
改行後の文 (ここでは「となり」から始まる文) は\noindent
しないとキモい。
section
内で\label
を付けて\ref
する。
~\cite
しないと禁則処理の問題が起こる。
ちなみにMSWordでは「改行なしスペース」と呼ばれている特殊文字で,Ctrl+Shift+スペースで入力できる。
$n$-gram
のようにハイフンを途中に含む単語が行末に来そうなときに,ハイフンで行が切れるとダサいと感じる人も少なくない。そういうときは\mbox{$n$-gram}
とすると改行が抑制される。よく使う単語なら\newcommand
しても良いだろう。
ハイフンっぽい文字の使い分けについては以下のページが詳しい。
↓subcaption
を使うべきです (subfigure
は時代遅れ)
\begin{figure}[h]
\begin{minipage}{0.5\hsize}
\begin{center}
\includegraphics[width=\columnwidth]{Reset.jpg}
(a) カラー画像
\end{center}
\end{minipage}
\begin{minipage}{0.5\hsize}
\begin{center}
\includegraphics[width=\columnwidth]{Gray.jpg}
(b) グレースケール画像
\end{center}
\end{minipage}
\caption{グレースケール変換}
\label{fig:rgb2gray}
\end{figure}
\shortstack{電動機負荷電流 \\ $I_m(A)$}
p以外のlcrを使うと\newline
が効かないので注意
http://tex.stackexchange.com/a/2442
\begin{tabular}{p{8em}p{13em}}
hoge \newline hoge hoge hoge & fuga fuga fuga fuga
\end{tabular}
表のセル結合との相性が最悪なので,注意すること.解決方法としては以下の2つが考えられる.
- 明示的な改行をあきらめる (
\begin{tabular}{p{3cm}p{4cm}}
のように指定すると,固定幅で自動的に改行される) - セル結合をあきらめる (
cmidrule{2-3}
などと組み合わせて誤魔化す?)
\begin{figure*}
\end{figure*}
LaTeXのメモ - Multicols環境での図の張り付け方法など
ただし,[!h]
を付けると別ページに移動させられたり,付けなかったら意図した通りに付いたりして,挙動が怪しい.multicol
を使うほうが良い場合もあるかもしれない.
\usepackage{multicol}
\begin{document}
\begin{multicols}{2}
% 図表を始めたい
\end{multicols}
\begin{figure}
\end{figure}
\begin{multicols}{2}
% 図表終わり
\end{multicols}
\end{document}
http://tex.stackexchange.com/questions/30985/displaying-a-wide-figure-in-a-two-column-document
MatplotlibでLaTeX用に出力したPDFをPowerPointなどに貼り付けたいときはImageMagickを使うと簡単だが,Windows版ではGhostScriptにパスを通す必要がある.
PATH=%PATH%;\texlive\2014\tlpkg\tlgs\bin
convert -density 400 a.pdf a.png
スライド向けの図を作るときにはfigsize=(4,3)
にしておくことを勧める.figsize=(8,6)
では文字が小さくなりすぎて,スライド向きではない.
フルネーム + abbr でググると見つかる.
縦書き用のスタイルファイルであるtarticleでは,\rensuji
というコマンドが定義されている.\rensuji{A}\rensuji{B}...
みたいなのを繰り返したいときは,以下のようにすればよい.
% \rensujiを繰り返す
% \re{ABC123}で\rensuji{A}\rensuji{B}\rensuji{C}\rensuji{1}\rensuji{2}\rensuji{3}となる
% http://tex.stackexchange.com/questions/253203/how-to-repeat-over-all-characters-in-a-string
\makeatletter
\newcommand{\re}[1]{\@tfor\next:=#1\do{\rensuji{\next}}}
\makeatother
%
はコメントを表すが,次の行の先頭部分にあるスペースも無視する.\newcommand
が長くなる場合に,行末に%
が置いてある理由はこれ.
\makeatletter
\renewcommand{\section}{%
\@startsection{section}{1}{\z@}%
{0.0\Cvs}{0.0\Cvs}%
{\normalfont\headfont\raggedright}}
\makeatother
http://www.yamamo10.jp/yamamoto/comp/latex/make_doc/basic/index.php#BASIC_COMMENT
設定
\usepackage{listings}
\lstset{%
basicstyle=\ttfamily\scriptsize,%
commentstyle=\ttfamily\scriptsize,%
tabsize=4,%
numbers=left,%
breaklines=true,%
showstringspaces=false,%
frame=single,%
xleftmargin=10pt,% 左にマージンを開けないと左カラムのフレームと右カラムの行番号が重なる
captionpos=b% キャプションの位置。デフォルトでは上
}
% How to change listing caption?
% https://tex.stackexchange.com/questions/64839
\renewcommand{\lstlistingname}{プログラム}
使い方
\begin{lstlisting}[language=Python,caption=キャプションです,label=prog:python-program]
# coding: UTF-8
def main():
printf("Hello, world!")
if __name__ == '__main__':
main()
\end{lstlisting}
実はfancyvrbパッケージのVerbatimでも結構良さげにできる。日本語を入力するならこっちの方が簡単かも。
\begin{figure}[h]
\begin{Verbatim}[frame=single,fontsize=\footnotesize]
> x<-1:10
> y<-4:13
> summary(x)
Min. 1st Qu. Median Mean 3rd Qu. Max.
1.00 3.25 5.50 5.50 7.75 10.00
\end{Verbatim}
\caption{\var{summary(x)}の実行結果}
\end{figure}
ほかにもmintedというパッケージもある
- LaTeXで載せたプログラムソースがページを跨ぐ場合の対処法について - muscle_keisukeの日記
- ソースコードの貼り付けができるmintedをpLaTeXで使ってみた - muscle_keisukeの日記
IEICEではtabbingというのを紹介していた。
\fbox{\includegraphics{foo.pdf}}
\documentclass
のオプションに draft
を付けて,\usepacakge{showframe}
するとよい。
改行を入れても良いところに \allowbreak
を設定する。
.bib
ファイルを編集して波括弧でくくる({ZDD}
)。
[!h]
を使ってもダメで,どうしてもその場に出したい場合は\usepackage{here}
して[H]
すると,その場に出る。
ただし,順番が入れ替わったりするリスクがあるので,使うなら全部に使うと決めておいたほうが良いかもしれないが,そうすると組版のセンスが悪い感じの仕上がりになる。
floatを使わないほうが簡単かもしれない。
\begin{center}
\includegraphics{foo.pdf}
\captionof{figure}{fig:foo}
\label{ラベルです}
\end{center}
それぞれ \gets
, \to
のほうがよい
% http://tex.stackexchange.com/questions/4728/how-do-i-number-equations-only-if-they-are-referred-to-in-the-text
\usepackage{autonum}
学会のテンプレートを使うときは caption=false
というオプションを付けたほうがよい。そうしないとcaptionパッケージに上書きされてしまう。
キャプションの上下の余白を減らしたいときには以下のオプションも有用かも
% ftp://ctan.tug.org/tex-archive/macros/latex/contrib/subfig/subfig.pdf
% 逼迫してきたらオプションに captionskip=0pt,farskip=0pt を追加する
\usepackage[caption=false,captionskip=0pt,farskip=0pt]{subfig}
algorithm環境のためにalgorithmパッケージを使う必要がある。
algorithmicの進化版であるalgorithmicxのレイアウトパッケージであるalgpseudocodeを使うと自動的にalgorithmicxが使われる。
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
%\algrenewcommand\algorithmicdo{}
%\algrenewcommand\algorithmicthen{}
\begin{algorithm}
\caption{Euclid’s algorithm}
\label{euclid}
\begin{algorithmic}[1] % The number tells where the line numbering should start
\Procedure{Euclid}{$a,b$} \Comment{The g.c.d. of a and b}
\State $r\gets a \bmod b$
\While{$r\not=0$} \Comment{We have the answer if r is 0}
\State $a \gets b$
\State $b \gets r$
\State $r \gets a \bmod b$
\EndWhile\label{euclidendwhile}
\State \textbf{return} $b$\Comment{The gcd is b}
\EndProcedure
\end{algorithmic}
\end{algorithm}
- algorithm, algorithmic, algorithmicx, algorithm2e, algpseudocode = confused - TeX - LaTeX Stack Exchange https://tex.stackexchange.com/questions/229355/algorithm-algorithmic-algorithmicx-algorithm2e-algpseudocode-confused
- LaTeX でアルゴリズムを記述する http://chirimenmonster.github.io/2016/02/19/tex-sty-algorithm.html
- reference algorithm · PMOB/study-tex Wiki https://github.com/PMOB/study-tex/wiki/reference-algorithm
- 現代的LaTeXコードのすすめ https://prml.main.ist.hokudai.ac.jp/~ryo/contents/textech2016/textech.pdf
https://proofwiki.org/wiki/Symbols:Set_Operations_and_Relations
% \documentclass[uplatex,a4j,twocolumn,10pt]{jsarticle} を想定
% uplatexではなくplatexを使う場合はuplatexの指定を外す
% twocolumnオプションは2段組になるだけでなく,\sectionのフォントサイズのデフォルト値にも影響するので,適切に設定した方が良い
% ページの周りの余白を狭くする
% 数字はMS Wordの余白設定をパクった
%\usepackage[top=35.01truemm,bottom=30truemm,left=30truemm,right=30truemm]{geometry}
\usepackage[top=25.4truemm,bottom=25.4truemm,left=19.05truemm,right=19.05truemm]{geometry}
% 図表や式の周りの余白を狭くする
% お世話になることは多いと思うが,.styの中で書き換えると.texと頻繁に行き来しなければならないので,
% .texファイル側に書いたほうが良いと思う
% 図表と図表の間のマージン
%\setlength{\floatsep}{5pt}
% 図表と本文の間のマージン
%\setlength{\textfloatsep}{10pt}
% 図表のcaptionと図表本体の間のマージン
%\setlength{\abovecaptionskip}{0pt}
% 図表のcaptionと本文の間のマージン
%\setlength{\belowcaptionskip}{0pt}
% 式の上の余白
%\setlength{\abovedisplayskip}{5pt}
% 式の下の余白
%\setlength{\belowdisplayskip}{5pt}
% amsmathのalignの中で改ページできるようにする
%\allowdisplaybreaks
% ページ内の図表の割合の設定
% まだお世話になったことが無いので試したことがない
% http://www.ice.is.kit.ac.jp/~umehara/misc/comp/latex.html
%\renewcommand{\topfraction}{1.0}
%\renewcommand{\bottomfraction}{1.0}
%\renewcommand{\dbltopfraction}{1.0}
%\renewcommand{\textfraction}{0.01}
%\renewcommand{\floatpagefraction}{1.0}
%\renewcommand{\dblfloatpagefraction}{1.0}
%\setcounter{topnumber}{5}
%\setcounter{bottomnumber}{5}
%\setcounter{totalnumber}{10}
% 行間を狭くする
% スペース節約の効果は大きいのだが,これ以上狭くすると,さすがにクレームが来ると思う
%\renewcommand{\baselinestretch}{0.85}
% Times系フォントを使う.研究室の方針に従ってください.
% mathptmxを使っていない理由は\vectのマクロ定義のコメントを参照.
\usepackage{newtxtext}
%\usepackage{newtxmath}
% \sectionの欧文をサンセリフ体からセリフ体にする.
% サンセリフ体というのはゴシック体みたいなやつのこと.jsarticleのデフォルトでは\sectionはサンセリフ体.
\renewcommand{\headfont}{\bfseries}
% \sectionの後ろに"."を付ける.
% http://tex.stackexchange.com/questions/24439/how-to-add-a-dot-after-the-section-number
\usepackage{titlesec}
\titlelabel{\thetitle.\quad}
% 表題と報告者を書くためのマクロ
% 使い方
% \twocolumn[
% \createtitle{タイトル}
% \createproperty{日付 \\ 名前}
% ]
% ゴシック体+サンセリフ体にしたいときは\textsfにする
% ゴシック体+セリフ体にしたいときは\textbfにする
% \begin{center}~\end{center}は余白が大きすぎたので\centeringにした
\newcommand{\createtitle}[1]{{\centering\textsf{\Large#1}\par}}
% \raggedleft#1\parは余白が小さすぎたので\begin{flushright}~\end{flushright}にした
\newcommand{\createproperty}[1]{\begin{flushright}#1\end{flushright}}
% テーブルの中で特定のセルだけ中央揃え
\newcommand{\cellcenter}[1]{\multicolumn{1}{c}{#1}}
% ~(チルダ)を入れると,その箇所での改行を抑制する(「図(改行)1」みたいになるとダサいので)
\newcommand{\refeq}[1]{(\ref{#1})~式}
\newcommand{\reffig}[1]{図~\ref{#1}}
\newcommand{\reftab}[1]{表~\ref{#1}}
% n-gramのnを数式フォントにするかどうかで揉めたら変える
% \mboxは途中で改行を入れないためのコマンド
% \newcommand{\ngram}{\mbox{$n$-gram}}
\usepackage{amsmath}
% argmax, argminのargとmax/minの間に空白を入れるかどうかで揉めたら変える
\DeclareMathOperator*{\argmax}{arg\,max}
\DeclareMathOperator*{\argmin}{arg\,min}
% ベクトルなどの太字に何を使うべきかで揉めたら変える
% bmパッケージの\bm{x}だと,Times系フォントを使うように設定していても,
% なぜかフォントがComputer Modernになるので,\boldmathで太字にする
% \boldmathを使ってもmathptmxパッケージだとなぜか太字にならないのでnewtxパッケージを使う
% 例:\usepackage{newtxtext,newtxmath}
% 参考:http://d.hatena.ne.jp/yascentur/20111215/1323879218
\newcommand{\vect}[1]{\mbox{\boldmath$#1$}}
% 行列の転置記号。T派,\mathrm{T}派,\top派など様々な流派がある
\newcommand{\tr}{\ensuremath{\mathrm{T}}}
% 偏微分記号で揉めたら変える
\newcommand{\pdiff}[1]{\ensuremath{\frac{\partial}{\partial#1}}}
% \eq{y=f(x)}と書くことで簡単に数式を書ける
\newcommand{\eq}[1]{\begin{equation}\begin{aligned}#1\end{aligned}\end{equation}}
% 期待値。イタリックはイマイチなので\mathbfにしている
\newcommand{\E}{\ensuremath{\mathbf{E}}}
\newcommand{\Var}{\ensuremath{\mathbf{Var}}}
% \subfloatコマンドを使えるようにする
\usepackage[caption=false]{subfig}
% 図の挿入を簡単にする
% 使い方 \simplefigure[位置指定]{ファイル名}{キャプション}{ラベル}
% 位置指定のデフォルトは [tbp] (http://tex.stackexchange.com/questions/172782)
\newcommand{\simplefigure}[4][tbp]{
\begin{figure}[#1]
\centering
\includegraphics[width=\columnwidth]{#2}
\caption{#3}
\label{#4}
\end{figure}
}
% 使い方 \simplesubfigure{ファイル名}{キャプション}
% http://qiita.com/nida_001/items/6cc78d12238281d34cab
\newcommand{\simplesubfigure}[2]{
\subfloat[#2]{
\includegraphics[width=0.48\textwidth]{#1}
}
}
\newcommand{\simplesubfigurespace}[3]{
\begin{figure*}[tbp]
\centering
#3
\caption{#1}
\label{#2}
\end{figure*}
}