1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[LaTeX]簡単に表を(並べて)挿入するマクロ

Last updated at Posted at 2023-03-15

表の関数,特に複数並べた表はそのままだと書くのが大変なのでマクロにしました.


%図を入れる用
\usepackage[dvipdfmx]{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{color}
\usepackage{comment}
\usepackage{amsmath}
\usepackage{listings}[langage=python3]
\usepackage{jlisting}[langage=python3]
\usepackage{url}
\usepackage{titlesec}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{diagbox}
\usepackage{aliascnt}
\usepackage{umoline}
\usepackage{pdfpages}
%これがないと警告がでてうざい
\makeatletter
\def\caption@documentclass{elsarticle}%
\makeatother
\usepackage[hang,small,bf]{caption}
\usepackage{ifthen,calc}
\usepackage{subcaption}
\usepackage{float}
\usepackage{amssymb}
\usepackage{hyperref}
\hypersetup{
  setpagesize=false,
  bookmarksnumbered=true,
  bookmarksopen=true,
  colorlinks=true,
  linkcolor=blue,
  citecolor=red,
}
\usepackage[noabbrev]{cleveref}
% crefをrefと見せかける
% hyperrefと併用できない感じか?
\let\nref\ref
\let\ref\cref

\captionsetup{compatibility=false} 
\renewcommand{\thesubfigure}{\alph{subfigure}}
%ソースコードをプログラムと読み替える
\renewcommand{\lstlistingname}{プログラム}
\def \pgpath{../../..}

%丸文字
\newcommand{\onum}[1]{\raise0.2ex\hbox{\textcircled{\scriptsize{#1}}}}
%ロリバさんの囲み文字大きさ固定化
\newcommand{\mybox}[1]{\framebox[1.2em]{\rule{0pt}{1.6ex}#1}}
%余白
\usepackage[top=7truemm,bottom=20truemm,left=20truemm,right=20truemm]{geometry}
\renewcommand{\thesection}{\arabic{section}.}
\renewcommand{\thesubsubsection}{\alph{subsubsection}.}
\makeatletter
%%%%% lstlistingのスタイル定義 ここから
\lstdefinestyle{ex}{
 frame={trbl},
 frameround={tttt},
 lineskip=-0.7ex,
 numbers=none
}


\lstset{%default
  language=Python,
  basicstyle={\ttfamily},
 breaklines=true,
 escapechar=\`,
 columns=[l]{fullflexible},
 keepspaces=true,
 showstringspaces=false,
 xrightmargin=0em,
 xleftmargin=1em,
 stepnumber=1,
 lineskip=-0.5ex,
 frame={lRtB},
 frameround={nnnn},
 numberstyle={\scriptsize},
 numbers=left
}
%tab内でfootnotemarkを使う
\makeatletter
\def\@xfootnote[#1]{%
  \protected@xdef\@thefnmark{#1}%
  \@footnotemark\@footnotetext}
\makeatother

%\captionsetup[subfigure]{labelformat=simple}
\renewcommand{\thesubfigure}{\alph{subfigure}}
% 参照フォーマット
\crefname{equation}{}{}
\crefname{figure}{}{}
\crefname{subfigure}{}{}
\crefname{table}{}{}
\crefname{subtable}{}{}
\crefname{appendix}{付録}{付録}
\crefname{subappendix}{付録}{付録}
\crefname{subsubappendix}{付録}{付録}
\crefname{subsubsubappendix}{付録}{付録}
\crefformat{lstlisting}{{プログラム}#2#1#3}
\crefrangeformat{lstlisting}{{プログラム}#3#1#4{--}#5#2#6}
\crefmultiformat{lstlisting}{{プログラム}#2#1#3}{, {プログラム}#2#1#3}{, #2#1#3}{, {プログラム}#2#1#3}

\begin{comment}
\crefformat{section}{#2#1#3{}}
\crefrangeformat{section}{#3#1#4{--}#5#2#6{}}
\crefmultiformat{section}{#2#1#3{}}{, #2#1#3{}}{, #2#1#3}{, #2#1#3{}}
\crefformat{subsection}{#2#1#3{}}
\crefrangeformat{subsection}{#3#1#4{--}#5#2#6{}}
\crefmultiformat{subsection}{#2#1#3{}}{, #2#1#3{}}{, #2#1#3}{, #2#1#3{}}
\crefformat{subsubsection}{#2#1#3{}}
\crefrangeformat{subsubsection}{#3#1#4{--}#5#2#6{}}
\crefmultiformat{subsubsection}{#2#1#3{}}{, #2#1#3{}}{, #2#1#3}{, #2#1#3{}}
\end{comment}
%-------------自分用--------------
%---------------------------------
%チルダ~
\def \tilde{$\sim$}

%空行-----------------
\newcommand{\lnskip}{\vskip\baselineskip}
%img[htbp(H)]{filename}{caption}{(fig:)label}{scale}------------------
\newcommand{\img}[5][htbp]{%
	\begin{figure}[#1]%
		\centering%
		\includegraphics[scale=#5]{#2}%
		\caption{#3}%
		\label{#4}%
	\end{figure}%
}
%someimg[option]{filename (1~.png)}{caption}{(fig:)label(1~)}{N個}{折り返し}{size}---------------------  
\newcommand{\filepath}[1]{#1}
%--------------------
%\someimg[scale]{filename}{caption}{(fig:)label}{pagesize}
\newcommand{\someimg}[5][]{%
	\begin{minipage}{#5\linewidth}%
		\centering
		\includegraphics[#1]{#2}%
		\subcaption{#3}%
		\label{#4}%
	\end{minipage}%
}
%--------------------
%表コマンド\begin{tab}{caption}{label}{lll}
\newenvironment{tab}[4][htbp]{\begin{table}[#1]\centering\caption{#2}\label{#3}\begin{tabular}{#4}}{\end{tabular}\end{table}}
%複数表 \begin{sometab}{caption}{tab:label}{lll}{pagesize} \end{sometab}
\newenvironment{sometab}[4]{\begin{minipage}[c]{#4\linewidth}\centering\subcaption{#1}\label{#2}\begin{tabular}{#3}}{\end{tabular}\end{minipage}}



\newenvironment{m}{\begin{equation*}\begin{split}}{\end{split}\end{equation*}}

\newenvironment{e}{\begin{equation}}{\end{equation}}
%------------------------------------------
%------------------------------------------
%sectionを1.というふうにする用
  \def\@seccntformat#1{%
  \@nameuse{@seccnt@prefix@#1}%
  \@nameuse{the#1}%
  \@nameuse{@seccnt@postfix@#1}%
  \@nameuse{@seccnt@afterskip@#1}}
  %-------------------------
  %sectionのあとのピリオド
  \def\@seccnt@prefix@section{}
  \def\@seccnt@postfix@section{.}
  \def\@seccnt@afterskip@section{\hskip1zw}
  %-----------------------------
  %subsub
  \makeatother

よくわからない人はなにも考えずこれをプリアンブルに貼っつけよう!
ドキュメントクラスは以下のようにすること
\documentclass[a4paper,10pt,titlepage,dvipdfmx]{jsarticle}
プリアンブル長いのが嫌な人はstyファイルをgithubにあげているのでこれをダウンロードして\usepackageで参照しても良いです.
https://github.com/soburi59/pLaTeX/blob/main/mystyle.sty

使用例

\begin{document}
\begin{tab}{caption}{label}{lll}
    \hline
    a & b & c\\ \hline\hline
    d & e & f \\
    g & h & i \\ \hline
\end{tab}


\begin{table}[htbp]
	\caption{caption}
	\label{label}
	\begin{sometab}{caption}{tab:label1}{lll}{0.45}
        \hline
        a & b & c\\ \hline\hline
        d & e & f \\
        g & h & i \\ \hline
    \end{sometab}
	\begin{sometab}{caption}{tab:label1}{lll}{0.45}
		\hline
		a & b & c\\ \hline\hline
		d & e & f \\
		g & h & i \\ \hline
	\end{sometab}
	\\
	\begin{sometab}{caption}{tab:label1}{lll}{0.45}
		\hline
		a & b & c\\ \hline\hline
		d & e & f \\
		g & h & i \\ \hline
	\end{sometab}
	\begin{sometab}{caption}{tab:label1}{lll}{0.45}
		\hline
		a & b & c\\ \hline\hline
		d & e & f \\
		g & h & i \\ \hline
	\end{sometab}
\end{table}

表示

image.png

引用

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?