LoginSignup
0
2

LaTeX:プリアンブルの紹介1 pLaTeX+jsarticle

Last updated at Posted at 2023-08-31

はじめに,LaTeXの使用目的

大学などでレポートを書く際にLaTeXをたまに使用しています.
今まで自分が使いやすいようにプリアンブルをいじってきたので参考になれば幸いです.

プリアンブルは今後も改造していくので,変更があったら記事を更新していきます!
また,使用・作成しているコマンドを解説した記事を今後追加しようと考えてます.

pLaTeXからLuaLaTeXに移行したので新しく記事でLuaLaTeX用のプリアンブルを紹介していこうと思います!

LaTeX:プリアンブルの紹介2 LuaLaTeX+ltjsarticle

最終更新日:2024年6月17日
<更新内容>
新しいコマンドを追加.見出しの書式の設定が複雑になっていたので,titlesecを使って簡略化しました..

LaTeXの使用環境

使用していたLaTeXエンジンはpLaTeX,文書クラスはjsarticleです.
Windows 11とMac OS Sonomaで動作確認出来ていました.

工夫した点

一時期physicsパッケージが便利で良く使っていたのですが,physicsパッケージとsiunitxパッケージを両立して使おうとするとエラーが出現し,両者を共に使う事は出来ませんでした.そこでphysicsは諦めてsiunitxを残したまま,成るべく自分が頻繁に使っていたphysicsのコマンドが同じ様に使える似たコマンドを設定しました.

プリアンブル

目次

  1. 使用しているパッケージ
  2. コマンドの設定
  3. コマンドの解説

使用しているパッケージ

\makeatletter %定義に@が現れる際に必要
\def\caption@documentclass{elsarticle} %エラー回避,,警告を抑止
\makeatother

%%%%%%%%%%%%%%%%%%%%用いるパッケージ%%%%%%%%%%%%%%%%%%%%
%ベース
\usepackage{savesym} %エラー回避のため,念のため
\usepackage{comment} %複数行のコメントアウト
\RequirePackage{fix-cm}

%レイアウト設定
\usepackage[top=20truemm,bottom=20truemm,left=25truemm,right=25truemm,truedimen]{geometry} %高機能なレイアウトの変更
\usepackage{bxpapersize} %今後出力用紙サイズの設定を適切に行うために,念のため
\usepackage{multicol} %多段組
\usepackage{vwcol} %多段組の拡張
\usepackage{balance} %文章の高さを揃える
\usepackage{setspace} %一部の行間スペースの調整
\usepackage{chngpage} %ページ設定

%グラフィックス
\usepackage[dvipsnames,dvipdfmx]{xcolor} %高機能な色変更
\usepackage[dvipdfmx]{graphicx} %テキストや図の拡大縮小・回転
\usepackage{here} %図や表の配置オプション,floatも読み込まれる
\usepackage[absolute,overlay]{textpos} %textpos 絶対座標指定モード

%図やPDFファイルの読み込み
\usepackage{grffile} %読み込む写真のファイル名によるエラー回避,念のため
\usepackage{pdfpages} %PDFファイルの読み込み,多機能
\usepackage{wrapfig} %図に大して文の回り込み
\usepackage[hang,small,bf]{caption} %subcaption
\usepackage[subrefformat=parens]{subcaption}
\captionsetup{compatibility=false}

%表
\usepackage{longtable} %複数ページに渡る表
\usepackage{booktabs, multirow} %高機能な表
\usepackage{threeparttable} %上2つで手が届かない表の微調整
\usepackage{makecell} %列見出しの作成やセル内テキストの配置
\usepackage{hhline} %二重罫線
% \usepackage{nicematrix} %nicetabular使うため
%excel2latexで必要
\usepackage{bigstrut}
\usepackage{colortbl} % 表の色付け

%見出し,段落など
\usepackage[compact]{titlesec} %見出しのカスタマイズ
\usepackage{indentfirst} %何故か段落で字下げされないので強制的に
\setlength{\parskip}{0zw} %段落間余白
\parindent = 1zw %段落の字下げ量

%箇条書き
\usepackage[shortlabels,inline]{enumitem} %高機能な箇条書き,shortlabelsは衝突回避
\setlist[itemize]{leftmargin=*} %itemizeを左側にずらす
\setlength{\leftmargini}{20pt} %左余白を調節する.
\setlength{\labelsep}{5pt} %6. itemと文字の間
\setlength{\itemsep}{0pt} %ブロック間の余白

%枠ボックス
\usepackage{ascmac} %複数行や数式環境で枠で囲う
\usepackage{fancybox} %部分的に枠で囲う

%数式・フラフ
\usepackage{amsmath,amssymb,onlyamsmath} %高機能な数式環境,フォントamssymb
\usepackage{mathtools} %数式環境の拡張
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\usepackage{empheq} %場合分け,各式に数式番号
\usepackage{bm} %太字のベクトル表記
\usepackage{esint} %様々な積分記号
\usepackage{derivative} %微分積分,偏微分
\usepackage{nicematrix} %複雑な行列
\usepackage{siunitx} %SI単位系
\usepackage{textcomp} %単位記号
\usepackage[version=4]{mhchem} %化学式
\everymath{\displaystyle} %数式の書体
\usepackage{exscale} %大型演算子のフォントサイズ調整用
\usepackage[thicklines]{cancel} %数式に取り消し線,対角線を引く
\usepackage{tikz} %グラフを直接書く
\usetikzlibrary{intersections,calc,arrows.meta,positioning,shapes.arrows,bending}%tikzの機能

%リンク参照
\usepackage{xurl} %URL
\renewcommand\UrlFont{\mcfamily}
\usepackage{footnote} %脚注
\usepackage[super]{cite} %複数の文献を引用
\usepackage[hidelinks]{hyperref} %ハイパーリンク機能,hidelinkで色をつけない
\usepackage{pxjahyper} %hyperrefの機能を拡張,日本語文字化け回避
\hypersetup{
	bookmarksopen=false, %ブックマークを開く
	colorlinks=false, %リンクのテキストに色をつけるか,リンクに枠がつくか
	linkcolor=black, %内部参照リンク用のカラー
	citecolor=black, %文献参照リンク用のカラー
	filecolor=black, %ローカルファイル参照リンク用カラー
	urlcolor=black %外部参照urlリンク用カラー
}
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{naturalnames}{hyperref}
\hypersetup{pdfauthor={Name}}

%文字フォント
\renewcommand{\bfdefault}{bx} %\bfdefault を “bx” に戻す,太字エラー回避
\usepackage[deluxe]{otf} %和文が2から5書体に増える
\usepackage[T1]{fontenc} %T1エンコーディング,Mac環境でエラー回避
%\usepackage{lmodern}使わない,Latin Modernフォント
\usepackage{newtxtext,newtxmath} %Times系フォント newtxtext,newtxmath
% \usepackage{exscale} %大型演算子のフォントのスケール newtx使う場合は不要.
\usepackage{type1cm} %欧文フォントのサイズ指定のエラー回避
%\usepackage[prefernoncjk]{pxcjkcat} %和文欧文扱いの制御, uplatex用
\usepackage{setspace} %行間隔の調整
\usepackage{pxrubrica} %漢字にルビをつけられる
\usepackage{ulem} %下線,波線,打ち消し線,上線
\usepackage{jumoline} %ulem,日本語で複数行に渡る線を引く
\setlength{\UnderlineDepth}{3pt}
\usepackage{listings} %コードの貼り付け
\lstset{
    basicstyle={\small\ttfamily},
    columns={fullflexible},
    frame=tlrb,
    rulecolor=\color{black},
    backgroundcolor=\color{black!10},
    breaklines = true,
    numbers = left,
    stepnumber = 1
}

コマンドの設定

%%%%%%%%%%%%%%%%%%%%コマンドの設定%%%%%%%%%%%%%%%%%%%%
\makeatletter %定義に@が現れる際に必要

% 余白
\setlength\floatsep{1zw} % 図と図の間のスペース
\setlength\textfloatsep{1zw} % 本文と図の間のスペース
\setlength\intextsep{0.5zw} % 本文中の図のスペース
\setlength\abovecaptionskip{0truemm} % 図とキャプションの間のスペース
\setlength{\abovedisplayskip}{2pt} % 数式の上部余白
\setlength{\belowdisplayskip}{2pt} % 数式の下部余白

%見出しの書式
%明朝体はmcfamily,ゴシック体はgtfamily
%太字はbfseries,イタリック体はitshape,ローマン体はrmfamily,スモールキャピタルはscshape,サンセリフ体はsffamily,スラント体はslshape,タイプライター体はttfamily
%section
\titleformat{\section}[hang]{
  \normalsize\bfseries\gtfamily}{\arabic{section}.}{0.5zw}{}
\titlespacing*{\section}{0zw}{1.5zw}{0zw}
%subsection
\titleformat{\subsection}[hang]{
  \normalsize\bfseries\gtfamily}{\arabic{section}.\arabic{subsection}.}{0.5zw}{}
\titlespacing*{\subsection}{0zw}{1zw}{0zw}
%数式を含む見出しを作りたいとき
\newcommand{\numsection}[1]{\section{\texorpdfstring{#1}{TEXT}}}
\newcommand{\numsubsection}[1]{\subsection{\texorpdfstring{#1}{TEXT}}}
%課題専用の見出し

%勝手に改行を防ぐ
% \patchcmd{\section}{\clearpage}{}{}{}
% \patchcmd{\subsection}{\clearpage}{}{}{}
% \patchcmd{\section}{\cleardoublepage}{}{}{}
% \patchcmd{\subsection}{\cleardoublepage}{}{}{}

%文字
\newcommand{\rubym}{\ruby[m]} %モノルビを使う.
\newcommand{\red}[1]{\textcolor{red}{#1}} %赤いテキスト
\newcommand{\blue}[1]{\textcolor{blue}{#1}} %青いテキスト
\newcommand{\delete}[1]{\Midline{#1}} %取り消し線(日本語文章)
\newcommand{\smath}[1]{\hbox{\sout{$\displaystyle #1$}}} %取り消し線(数式環境内)
%キーワードや暗記したい単語の書式
\newcommand{\keyw}[1]{\textcolor{blue}{#1}} %キーワード
\newcommand{\Ukeyw}[1]{\textcolor{blue}{\underline{\textcolor{blue}{\: #1 \:}}}} %キーワード,下線付き
\newcommand{\memw}[1]{\textcolor{CarnationPink}{#1}}%暗記ワード
\newcommand{\Umemw}[1]{\textcolor{Black}{\underline{\textcolor{CarnationPink}{\: #1 \:}}}} %暗記ワード,下線付き
\newcommand{\vect}[1]{\overrightarrow{#1}}
\newcommand{\cnm}[1]{\textcircled{\scriptsize{#1}}} %数字を丸で囲んだ文字
\newcommand{\degree}{^\circ}
\renewcommand{\hat}{\widehat}
\renewcommand\citeform[1]{\rm[#1]} % 上付きの文献参照に[]をつける

%括弧
\newcommand{\ab}[1]{\left(#1\right)} %()で括る
\newcommand{\bab}[1]{\left\{#1\right\}} %{}で括る
\newcommand{\Bab}[1]{\left[#1\right]} %[]で括る
\newcommand{\paraAb}[1]{\noindent <#1>} %<タイトル>
\newcommand{\paraAB}[1]{\noindent <#1>\\} %<タイトル>改行
\newcommand{\paraABt}[1]{\noindent <#1>\\\indent} %<タイトル>改行+インデント

%表と図の参照
\renewcommand{\figurename}{}
\renewcommand{\tablename}{}
\newcommand{\figref}[1]{\figurename\ref{#1}}%図の参照
\newcommand{\tabref}[1]{\tablename\ref{#1}}%表の参照
\renewcommand{\thefigure}{\thesection.\arabic{figure}}
\renewcommand{\thetable}{\thesection.\arabic{table}}
\renewcommand{\theequation}{\thesection.\arabic{equation}}
\@addtoreset{figure}{section}
\@addtoreset{table}{section}
\@addtoreset{equation}{section}
\captionsetup[figure]{format=plain, labelfont=md, labelformat=simple, labelsep=period, font=normalsize}
\captionsetup[table]{format=plain, labelfont=md, labelformat=simple, labelsep=period, font=normalsize}

%itemizeなどで説明を書くために良く使うコマンド
\newcommand{\mdef}{\mbox{}\\}

%目次
\renewcommand{\headfont}{\bfseries\large\mcfamily} %目次のSectionの書式
\newcommand{\tableofcontentswithouttitle}{
\@mkboth{\contentsname}{\contentsname}
\@starttoc{toc}} %"目次"を消す
\newcommand{\tocnew}[2]{ %新しい目次のコマンド,目次を任意の複数行で書き,tocdepthを設定する.
\leftline{\bfseries\Large 目 次}
\setcounter{tocdepth}{#2}
\begin{multicols}{#1}
\tableofcontentswithouttitle
\end{multicols}}

%数式
\DeclareRobustCommand{\percent}{\text{\fontfamily{jkp}\selectfont 
\%}} % %のフォントを直す.
\DeclareRobustCommand{\Percent}{\text{\fontfamily{jkp}\selectfont 
\,\%}} % [%]のフォントを直す.
%微積
\newcommand{\dd}[1]{\odif{#1}} %微分d
\newcommand{\pp}[1]{\pdif{}{#1}} %偏微分p
\newcommand{\dv}[3][1]{\odv[order={#1}]{#2}{#3}} %常微分係数d/d
%\newcommand{\dvn}[2]{\odv[switch-*=true]{#1}{#2}} %常微分係数
\newcommand{\dvp}[3][1]{\pdv[order={#1}]{#2}{#3}} %偏微分係数p/p
%\newcommand{\dvpn}[2]{\pdv[switch-*=true]{#1}{#2}} %偏微分係数
\newcommand{\dvl}[3][1]{\mdv[order={#1}]{#2}{#3}} %ラグランジュ微分
%行列
\newcommand\mx[1]{\begin{matrix}#1\end{matrix}} %行列
\newcommand\pmx[1]{\begin{pmatrix}#1\end{pmatrix}} %(行列)
\newcommand\bmx[1]{\begin{bmatrix}#1\end{bmatrix}} %[行列]
\newcommand\vmx[1]{\begin{vmatrix}#1\end{vmatrix}} %行列式
\newcommand\Vmx[1]{\begin{Vmatrix}#1\end{Vmatrix}} %行列ノルム
%文章中の式に式番号を入れる
\def\EqNumText{\refstepcounter{equation}\cdots\tagform@\theequation}
%数式を呼び出した際の書式
\newcommand{\Eqref}[1]{\eqref{#1}}
% SI単位系,数式や関数を含める
\newcommand{\SIeq}[2]{\SI[parse-numbers=false]{#1}{#2}}
% 虚数と実部
\let\Re\relax
\DeclareMathOperator{\Re}{Re}
\let\Im\relax
\DeclareMathOperator{\Im}{Im}
\newcommand{\const}{\mathrm{const.}} %定数

% 確率統計
\newcommand{\npr}[2]{{}_{#1} P_{#2}}
\newcommand{\ncr}[2]{{}_{#1} C_{#2}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\Z}{\mathbb{Z}}

%表の書式
\newcommand{\CenterRow}[2]{
  \dimen0=\ht\strutbox%
  \advance\dimen0\dp\strutbox%
  \multiply\dimen0 by#1%
  \divide\dimen0 by2%
  \advance\dimen0 by-.5\normalbaselineskip
  \raisebox{-\dimen0}[0pt][0pt]{#2}} %行間が大きい場合,文を行間の中央に寄せる.数字は行数
\newcommand{\cellspace}{\rule[-10pt]{0pt}{28pt}} %表の中に数式を入れる場合,行間をつくる
\newcommand{\Gray}{\columncolor[gray]{0.9}}

%cline 表のセルに色付けると消えるのを回避
\def\@cline#1-#2\@nil{%
  \noalign{\vskip-\arrayrulewidth}
  \omit
  \@multicnt#1%
  \advance\@multispan\m@ne
  \ifnum\@multicnt=\@ne\@firstofone{&\omit}\fi
  \@multicnt#2%
  \advance\@multicnt-#1%
  \advance\@multispan\@ne
  {\CT@arc@\leaders\hrule\@height\arrayrulewidth\hfill}%
  \cr}

\makeatother

コマンドの解説

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